I am pretty new to SAS Programming. I have couple of queries that i have come across. Could you please help me to understand below quries?
1. What would the title and output of the following code be? Why?
Code:
data txns;
do amt = 40000, 42000, 48000;
output;
end;
run;
data process;
set txns;
if amt >= 50000 then do;
%let title_suffix = NOTE: Large Transaction Amounts!!;
large_tran_flag = 'Y';
end;
run;
title "Transaction Report &title_suffix";
proc print data = process;
run;
My answer to above question is: Title: "Transaction Report " and the value of Output is " " (Space). Correct me if i am wrong. Appreciate if any one explains me step by step execution.
2. Given the following array, how would you total the values?
array abc(5) ( 12 5 . 17 20);
I understand the its the 5th array of ABC. But i didn't understand whats with in the parenthesis. Could you any one explain whats happening ?
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
1. The PROC PRINT will print all three data values, so your statement that the output will be " " is incorrect.
2. You completely misunderstand the statement. abc is defined as an array of 5 elements and their initial values are 12, 5, missing, 17, and 20. You can sum them by iterating across the array or using SUM OF, depending on what you want the answer to be (missing values changes things, often, in SAS).
1. The PROC PRINT will print all three data values, so your statement that the output will be " " is incorrect.
2. You completely misunderstand the statement. abc is defined as an array of 5 elements and their initial values are 12, 5, missing, 17, and 20. You can sum them by iterating across the array or using SUM OF, depending on what you want the answer to be (missing values changes things, often, in SAS).
Thanks a lot Robert for quick reply.
1st Question:
a. Just to confirm, Is my answer for Title correct.? Please confirm.
b. When it comes to Output, Proc PRINT Data = Process. Below is my understaning based on your answer .. please correct me if i am wrong.. I am just going step by step.
1. Data Txns section assigned the 3 values to Amt i.e. AMT field contains 40000, 42000, 48000.
2. Output displays all 3 values in Data Txns section itself right ?
3. Data Process section :- Set Txns statement displays all 3 values as Txns contains output statement.
4. condition is failed here since amt doesnt contain >=50000. so it skips complete If condition.
5. Then the value " Transaction Report " will be moved to Title ( Title_Suffix is empty as it didn't set any value in the If condition logic)
6. At last, PROC PRINT Data = Process :- Process section values will be moved into Data (i.e Step 3 result will be printed. Since process section contains Set Txns)
So the Title Value is " Transaction Report " and Output = 40000, 42000, 48000.
2nd Question:
I am sorry! I misunderstood. In this case, It has missing/Blank value, But when it comes to total should i say the total of array is 54 ? or Should i say as a Note "Missing values changes often in SAS" in addition with Total as 54?
Could you please let me know what's the best answer to say in the interview for this question?.
And the iteration logic mentioned below. Please correct me if anything wrong in it.
Data ArraySum
Array abc(5) (12 5 . 17 20);
Do i = 1 to 5;
Array_total(i) = Array_Total(i) + abc(i);
End;
PRINT Array_Total(i); --> 54
Run;