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!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 15095 views
  • 4 likes
  • 4 in conversation