BookmarkSubscribeRSS Feed
EricB40
Fluorite | Level 6

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?

2 REPLIES 2
malorygraybush
Calcite | Level 5

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;

 

EricB40
Fluorite | Level 6

You are a saint. Thank you.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 665 views
  • 3 likes
  • 2 in conversation