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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 13770 views
  • 4 likes
  • 4 in conversation