Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SAS Programming - Basic Questions

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
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    Post subject: SAS Programming - Basic Questions
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: 7904
Location: Bellevue, IA

PostPosted: Fri Mar 18, 2016 11:32 pm    Post subject:
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    Post subject:
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: 1445
Location: Azeroth

PostPosted: Tue Mar 29, 2016 9:18 pm    Post subject:
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.

https://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    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts INCLUDE condition questions van bui DFSORT/ICETOOL 1 Thu Jun 30, 2016 9:52 am
No new posts Event-driven programming (BTS) VS (ST... Rohit Umarjikar CICS 2 Sat Jun 11, 2016 2:05 am
No new posts Where can i find Interview questions ... Elixir Mainframe Interview Questions 4 Sat Feb 20, 2016 12:38 am
This topic is locked: you cannot edit posts or make replies. Canada mainframe systems programming ... Gary Jacek Mainframe Jobs 0 Sat Jan 30, 2016 4:26 am
No new posts File Aid DB2 Questions niks_jude Mainframe Interview Questions 1 Mon Aug 24, 2015 5:13 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us