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;
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.
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.
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:
and the latter, I get the correct answer is A , why ?
Thank you , could you tell me why the answer is A ?
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.
Thank you for your help.
Thank you very much for telling . I appreciate.
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!
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.