BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
knveraraju91
Barite | Level 11
Spoiler

data one;
input avalc $ aval;
datalines;
r1 1
r2 2
r3 3
r4 4
;


proc sql ;
select count(distinct avalc) into: cntt trimmed from one;
select distinct avalc into :param1 -:param&cntt.
from one;
quit;

%put &param1;
%put &param2;
%put &param3;
%put &param4;


data two three four six;
set one;
if avalc='r1' then output two;
if avalc='r2' then output three;
if avalc='r3' then output four;
if avalc='r4' then output six;
run;

%macro want;
data final;
set two three %if %symexist (param3) %then %do; four;%end;    %if %symexist (param4) %then %do; six; %end;;
run;
%mend;
options mprint mlogic symbolgen;
%want;

Dear

when I run macro(%want) at the bottom of my pgm i am getting error.  Please suggest Thank you

 

output expected  from macro %want

 

data final;
set two three four six;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you wanted that code then why did you insert those two extra semi-colons?

Plus the %do/%end blocks seem like overkill.

%macro want;
data final;
  set two three 
%if %symexist (param3) %then four ;    
%if %symexist (param4) %then six ;
  ;
run;
%mend;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

If you wanted that code then why did you insert those two extra semi-colons?

Plus the %do/%end blocks seem like overkill.

%macro want;
data final;
  set two three 
%if %symexist (param3) %then four ;    
%if %symexist (param4) %then six ;
  ;
run;
%mend;
Kurt_Bremser
Super User

Since version 9.4M5, you do not need a macro definition, %if %then %do %end can be used in open code:

data final;
set
  two
  three
%if %symexist (param3) %then %do; 
  four
%end;
%if %symexist (param4) %then %do;
  six
%end;
;
run;
%mend;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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