Given the SAS data set SASDATA TWO:
SASDATA TWO
XY
---- The following SAS program is submitted:
data sasuser.one two sasdata.three;
set sasdata two;
if x = 5 then output sasuser.one;
else output sasdata two;
run;
What is the result?
First check the syntax of what you typed. Is it actually the code exactly as it appeared in the source?
The Set statement would attempt to read data, in your code, from two data sets, one named Sasdata and the other named TWO. If there is is not any error at that step (such as same named variable with different types) and if one or both of those data sets contain a variable named X, not stated as a requirement, then if any values of x are 5 then write the record to the sasdata.one.
However the next statement, if accurate from the source, of Output SASDATA TWO will generate an ERROR because SASDATA is not on the Data statement and not available for output. So nothing actually gets replaced.
General hint for such questions: create small data sets and test the code. Personally I would never write to SASUSER but it should work.
@AnkitaSingh_901 wrote:
Given the SAS data set SASDATA TWO:
SASDATA TWO
XY
---- The following SAS program is submitted:
data sasuser.one two sasdata.three;
set sasdata two;
if x = 5 then output sasuser.one;
else output sasdata two;
run;
What is the result?
Hello,
I agree with @PaigeMiller, a few more details are needed because these details are important. For example, has a library been established for SASDATA before the DATA step is submitted? The assumption is that it has been established, but if not, the first ERROR that you will get is ERROR: Libref SASDATA is not assigned. If a library has been assigned for SASDATA, then the question becomes, is the SET statement supposed to be; SET SASDATA.TWO; (and does that exist) or are there two WORK data sets WORK.SASDATA and WORK.TWO and the SET statement is supposed to be SET SASDATA TWO; thus referencing the two temporary data sets? I can't really tell from the tips that were provided. After that, it depends from that point on whether there are two data sets WORK.SASDATA and WORK.TWO and if so, @ballardw's response is on point!
If you wish to try this for yourself, here is a sample program that I wrote to test out the code. It assumes SASDATA library an be established, it assumes you have access to c:\ (C: drive) on your PC if you are submitting the program code in Windows. If not, replace the location in the LIBNAME statement to point to a location (in quotes) that exist on your computer and that you have write access to. Also, it assumes that the SET statement in the original code is correct to reference two data sets SASDATA and TWO > set sasdata two;
The sample program below creates the SASDATA library, and creates the two temporary data sets SASDATA and TWO before the original program can be submitted.
libname sasdata 'c:\';
data two;
set sashelp.cars;
if _n_=1 then
do x=1 to 5;
output;
end;
run;
data sasdata;
set sashelp.cars(obs=2);
do x=1 to 5;
output;
end;
run;
data sasuser.one two sasdata.three;
set sasdata two;
if x = 5 then output sasuser.one;
else output sasdata two;
run;
Good Luck!
We can't possibly know what the output is, since we don't have the data sets.
You say: given the SAS data set SASDATA TWO — should that say SASDATA.TWO? Details are important.
Given the inquiry and the code - to me it looks like a lab question.
A bit more context is needed to answer the question.
The usual tip is top actual try the code and see for yourself.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.