BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil0917
Fluorite | Level 6

Hi Everyone,

   What I am trying to do is use an empty dataset as a "frame" (to set the variable order and lengths) and then append observations to that dataset with hardcoded data (using <variable>=<value> and output statements).  However, when I set the empty dataset and then try to add the variable and output statements, the resulting dataset always still has 0 observations.  

 

   Here is some example code, in which the "_out.WSTHP" is the original empty dataset (0 observations, but contains all of the variables that are described below) and I am trying to add an observation containing the subsequent data.  I would have thought the hardcoded lines and output statement would create an observation, but the resulting dataset is still empty.

 

Any ideas?

 

data _out.WSTHIP;
   set _out.WSTHIP;
   __StudyOID="dummy";
   __MetaDataVersionOID="1.3";
   __SubjectKey="dummy-102";
   __StudyEventOID="e_fu10y";
   __StudyEventRepeatKey="001";
   __FormOID="f_metabpar";
   __FormRepeatKey="001";
   __ItemGroupOID="g_wsthip";
   __ItemGroupRepeatKey="001";
   __LocationOID="Center.Admin";
   __UserOID="User.034";
   HIP=201;
   WSTHIP=1;
   WAIST=201;                           
   output;
run;   
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

As it stands, the SET statement ends the DATA step because there are no observations to read.  Yet you need the SET statement within the DATA step to define the variables properly.  The solution is to keep the SET statement within the DATA step, yet avoid executing it.  For example, change it to:

 

if 5=4 then set _out.WSTHIP;

 

View solution in original post

5 REPLIES 5
Astounding
PROC Star

As it stands, the SET statement ends the DATA step because there are no observations to read.  Yet you need the SET statement within the DATA step to define the variables properly.  The solution is to keep the SET statement within the DATA step, yet avoid executing it.  For example, change it to:

 

if 5=4 then set _out.WSTHIP;

 

Phil0917
Fluorite | Level 6

Thanks for the suggestion!  That did the trick!! 🙂

 

Thanks again!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, thats normal.  There are no obs being read, so nothing happens in the datastep.  Either create a datastep with your one record, then append or set that with your template, or you could use proc sql; insert into out.wthip __studyoid="abc"...; quit;

Shmuel
Garnet | Level 18

You can use next skilton code:

 

data _out.WSTHIP;
   set _out.WSTHIP end=eof;
output;
if eof then do;
.... enter here your code to assign new obs values...
output;
end;
run;
Phil0917
Fluorite | Level 6

Thanks for the suggestion!  I actually saw this method somewhere and tried it, but it still generated a 0 observation dataset.  I did get another suggestion in this thread that worked, but thanks anyway!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 13097 views
  • 4 likes
  • 4 in conversation