IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SAS Programming - Basic Questions


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Techelm

New User


Joined: 18 Mar 2016
Posts: 2
Location: India

PostPosted: Fri Mar 18, 2016 10:53 pm
Reply with quote

Hi All,

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 ?

Thanks!

code' d
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Mar 18, 2016 11:32 pm
Reply with quote

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).
Back to top
View user's profile Send private message
Techelm

New User


Joined: 18 Mar 2016
Posts: 2
Location: India

PostPosted: Sat Mar 19, 2016 5:28 am
Reply with quote

Robert Sample wrote:
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;

Thanks a lot once again for your help Robert.

Thanks!
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Tue Mar 29, 2016 9:18 pm
Reply with quote

Hi,

Your understanding of how the DATA step works is incorrect. DATA step and OUTPUT statement does not work that way.

Check this link which explains in detail how SAS DATA step works. This is the same material I used for learning SAS. It is step by step and detailed.

books.google.co.in/books?id=7WkfycHDQX4C&pg=PA22&lpg=PA22&dq=how+sas+works+inside+the+black+box&source=bl&ots=YGHyUzkE9L&sig=6_xT_TNikwW0J-QLmjGf1HQk294&hl=en&sa=X&ved=0ahUKEwjz6bqDn-bLAhWFcY4KHbHuC00Q6AEIKTAE#v=onepage&q=how%20sas%20works%20inside%20the%20black%20box&f=false
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Compiler and run JCL for basic PL/I p... PL/I & Assembler 10
No new posts Cobol-DB2 Programming - Better perfor... DB2 1
No new posts Learning about Systems Assembler prog... PL/I & Assembler 5
No new posts CICS file processing using applicatio... CICS 3
No new posts Comp interview questions Mainframe Interview Questions 5
Search our Forums:

Back to Top