BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tianerhu
Pyrite | Level 9
data sasuser.one sasuser.two other;
   infile datalines;
   if x eq 5 then output sasuser.one;
   if y lt 5 then output sasuser.two;
   output;
datalines;
5 2
3 1
5 6 
;
run;
title 'sasuser.on';
proc print data = sasuser.one;
run;
title 'sasuser.t';
proc print data = sasuser.two;
run;
title 'other';
proc print data = other;
run;

tianerhu_0-1619439514430.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

For the code as posted none of the answers is right.  

1501  data sasuser.one sasuser.two other;
1502     infile datalines;
1503     if x eq 5 then output sasuser.one;
1504     if y lt 5 then output sasuser.two;
1505     output;
1506  datalines;

NOTE: Variable x is uninitialized.
NOTE: Variable y is uninitialized.
NOTE: The data set SASUSER.ONE has 1 observations and 2 variables.
NOTE: The data set SASUSER.TWO has 2 observations and 2 variables.
NOTE: The data set WORK.OTHER has 1 observations and 2 variables.

Assuming that we add an INPUT statement before the first IF (or just replaces the INFILE statement) that reads the two columns of data into the variables X and Y then A is the right answer.

1511  data sasuser.one sasuser.two other;
1512     input X Y ;
1513     if x eq 5 then output sasuser.one;
1514     if y lt 5 then output sasuser.two;
1515     output;
1516  datalines;

NOTE: The data set SASUSER.ONE has 5 observations and 2 variables.
NOTE: The data set SASUSER.TWO has 5 observations and 2 variables.
NOTE: The data set WORK.OTHER has 3 observations and 2 variables.

The last OUTPUT statement will write one observation per line of data read to all three output datasets.

So each output dataset will get at least 3 observations.

 

As to why the first two datasets each get an additional two observations look at the IF conditions and see how many times they are true so that the the extra output statements that write to just one of the datasets runs.

 

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Wow, someone has come up with a totally unrealistic question designed to be extremely tricky for beginning students. Whoever created this question should be ashamed. Speaking as a non-beginner, I have no idea what this does, or why it happens, as I have never once in over 800 years of programming in SAS used INFILE without an INPUT statement.

 

 

--
Paige Miller
tianerhu
Pyrite | Level 9

yes, you are right, actually, at the begin, I think that there are no difference between the data(5 2, 3 1, 5 6)in a sas data set and in datalines. but later, I just find they are different between them---if we want to use the datallines, we need to add input statement, otherwise , we don't . why ?

the former , I get the following:

tianerhu_0-1619442254967.png

and the latter, I get the correct answer is A , why ?

 

tianerhu
Pyrite | Level 9

Thank you ,  could you tell me why the answer is A ?

Tom
Super User Tom
Super User

For the code as posted none of the answers is right.  

1501  data sasuser.one sasuser.two other;
1502     infile datalines;
1503     if x eq 5 then output sasuser.one;
1504     if y lt 5 then output sasuser.two;
1505     output;
1506  datalines;

NOTE: Variable x is uninitialized.
NOTE: Variable y is uninitialized.
NOTE: The data set SASUSER.ONE has 1 observations and 2 variables.
NOTE: The data set SASUSER.TWO has 2 observations and 2 variables.
NOTE: The data set WORK.OTHER has 1 observations and 2 variables.

Assuming that we add an INPUT statement before the first IF (or just replaces the INFILE statement) that reads the two columns of data into the variables X and Y then A is the right answer.

1511  data sasuser.one sasuser.two other;
1512     input X Y ;
1513     if x eq 5 then output sasuser.one;
1514     if y lt 5 then output sasuser.two;
1515     output;
1516  datalines;

NOTE: The data set SASUSER.ONE has 5 observations and 2 variables.
NOTE: The data set SASUSER.TWO has 5 observations and 2 variables.
NOTE: The data set WORK.OTHER has 3 observations and 2 variables.

The last OUTPUT statement will write one observation per line of data read to all three output datasets.

So each output dataset will get at least 3 observations.

 

As to why the first two datasets each get an additional two observations look at the IF conditions and see how many times they are true so that the the extra output statements that write to just one of the datasets runs.

 

tianerhu
Pyrite | Level 9

Thank you for your help.

Cynthia_sas
SAS Super FREQ
Hi:
If you found this question in one of the SAS Prep Guides, please send the book information (such as ISBN number and exact title) to Certification@sas.com so they can fix the publication or update the errata. (they'll need the book title, the ISBN, the page number with the question and the page number with the question solution).

My guess, however, is that this is either a very old Prep Guide or a sample question not written by SAS but from someone else's web site. We used to show test code writing to SASUSER (a long time ago) but stopped that practice because on EG, and on University Edition and SAS OnDemand users do NOT have write access to SASUSER and so code like this won't work. Several years ago, we changed our Prep Guide examples NOT to use SASUSER, so this is why I think there is something "off" with this question.

If you DID have an INPUT statement for X and Y, then the correct answer would be A, as @Ksharp has indicated. But, as written, none of the answers are correct.

Cynthia
tianerhu
Pyrite | Level 9

Thank you very much for telling . I appreciate.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 965 views
  • 6 likes
  • 5 in conversation