BookmarkSubscribeRSS Feed
ssc
Calcite | Level 5 ssc
Calcite | Level 5
Hi all,

I'm trying to append a single observation containing the value of a macro variable to an existing data set. My code (see below) works fine as long my input data set contains at least one observation, but fails if not.

Due to the context my program will run, I'm looking for a solution which works and
- ensures that type and length of data set variable VALUE in OUT is equal to INPUT
- does not need creating temporary data sets

Does anyone have an idea for a simple solution?

Many thanks!

Regards,
Stephan

/** sas code begin *******************************************/
%let mvar=test;

data INPUT; /*works */
length value $20;
value="obs1";
run;

data INPUT; /*works not*/
length value $20;
delete;
run;


data OUT;
set INPUT end=eof;
output;
if(eof) then do;
value=symget('mvar');
output;
end;
run;

/** sas code end *******************************************/
2 REPLIES 2
data_null__
Jade | Level 19
[pre]
%let mvar=test;

data INPUT; /*works */
length value $20;
do _n_ = 1 to 10;
value="obs1";
output;
end;
run;

data INPUT; /*works not*/
length value $20;
delete;
run;* cancel;


data OUT;
do while(not eof);
set INPUT end=eof;
output;
end;
value=symget('mvar');
output;
stop;
run;
proc print;
run;
[/pre]

To make it more APPEND like where you just add data to the end MODIFY is a good choice.

[pre]
data input;
if 0 then modify input;
value=symget('mvar');
output;
stop;
run;
[/pre] Message was edited by: data _null_;
DataShare
SAS Employee
Other way,

data OUT ;
if nc eq 0 or eof then
do;
value=symget('mvar');
output;
end;
set INPUT nobs=nc end=eof;
output;
run;

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