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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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