Hi everyone
I used this code to create a dataset called HOSP
data hosp;
do j = 1 to 1000;
AdmitDate = int(ranuni(1234)*1200 + 15500);
quarter = intck('qtr','01jan2002'd,AdmitDate);
do i = 1 to quarter;
if ranuni(0) lt .1 and weekday(AdmitDate) eq 1 then
AdmitDate = AdmitDate + 1;
if ranuni(0) lt .1 and weekday(AdmitDate) eq 7 then
AdmitDate = AdmitDate - int(3*ranuni(0) + 1);
DOB = int(25000*Ranuni(0) + '01jan1920'd);
DischrDate = AdmitDate + abs(10*rannor(0) + 1);
Subject + 1;
output;
end;
end;
drop i j;
format AdmitDate DOB DischrDate mmddyy10.;
run;
How do I create a temporary dataset called HOSP2 using "set"? I tried this:
data hosp;
set hosp2;
do j = 1 to 1000;
AdmitDate = int(ranuni(1234)*1200 + 15500);
quarter = intck('qtr','01jan2002'd,AdmitDate);
do i = 1 to quarter;
if ranuni(0) lt .1 and weekday(AdmitDate) eq 1 then
AdmitDate = AdmitDate + 1;
if ranuni(0) lt .1 and weekday(AdmitDate) eq 7 then
AdmitDate = AdmitDate - int(3*ranuni(0) + 1);
DOB = int(25000*Ranuni(0) + '01jan1920'd);
DischrDate = AdmitDate + abs(10*rannor(0) + 1);
Subject + 1;
output;
end;
end;
drop i j;
format AdmitDate DOB DischrDate mmddyy10.;
run;
proc print data=hosp2;
run;
But it did not work. Does anyone know how to fix this?
Documentation for the SET statement (https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p00hxg3x8lwivcn1f0e9axziw57y.htm) describes that SET is used to read observations, not to create a data set.
What is your definition of a "temporary data set?" A common working definition is a "data set not saved when the SAS session terminates," and these "temporary data sets" can be created in the WORK library, as its contents are not saved across (or after) SAS sessions. Whenever a data set is created (or otherwise referenced), and no SAS library is explicitly denoted (in dot notation like LIBRARY.DATASET), then the WORK library is applied by default (i.e., WORK.DATASET).
For example, your Hosp data set is temporary because no library is specified when Hosp is created, so the data set you have created is WORK.Hosp.
Thus, to create a temporary data set Hosp2, you need to only need to reference Hosp2 in the DATA statement:
data Hosp2;
You are a saint. Thank you.
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.
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.
Ready to level-up your skills? Choose your own adventure.