BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
%MACRO OUTPUT(DSN,MARKET,GROUP1,GROUP2,GROUP3);

%DO I=1 %TO 3;
%put GROUP= &&GROUP&I;
%IF %NRQUOTE(&&GROUP&I)= %THEN %DO;
%LET VGROUP&I = ;
%END;
%ELSE %DO;
%LET VGROUP&I = "&&GROUP&I"N;
%END;
%put VGROUP= &&VGROUP&I;

%END;


%mend output;
%OUTPUT(ANTIF,ANTI-FUNGAL
,ABC,DE F,HIJ);


How to create another macro variable name which resolves as follows:
'ABC,'DEF',HIJ'
i.e
name resolves to 'ABC,'DEF',HIJ'
12 REPLIES 12
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SASPhile,

You wrote: How to create another macro variable name which resolves as follows:
'ABC,'DEF',HIJ' i.e name resolves to 'ABC,'DEF',HIJ'

%let New='ABC,'DEF',HIJ';

Is this what you need?

Sincerely,
SPR
SASPhile
Quartz | Level 8
Yes.
But macro variable 'NEW' are the postional parameters. They may change whenever the user passes a new value.
So it should be dynamic.
SPR
Quartz | Level 8 SPR
Quartz | Level 8
How about this within your macro:

%let new="&GROUP1.","&GROUP2.","&GROUP3.";?
SASPhile
Quartz | Level 8
The reason to create %let name is to use it in subsetting the dataset in the next step.
i.e where condition where rolrod in (&name);

The problem with that is:

there could be group1 to group9 values.but sometimes user passes only 6 or 5 or 3 values .
so in the %let name statement if we define from group1 to group9

and only three values are passed
the macro varible will have missing values in the end like this

%let name= 'ABC','DEF',HIJ',,,,,, ;
chang_y_chung_hotmail_com
Obsidian | Level 7

%*-- comma separated quoted values --*;
%macro csqv(key1,key2,key3,key4,key5,key6,key7,key8,key9);
   %local i k;
   %do i = 1 %to 9;
      %let k = &&key&i;
      %if &k= %then %goto cont;
      %if &i>1 %then %*;,;
      %*;%sysfunc(quote(&k))
      %cont:
   %end;
%mend csqv;
%put ***%csqv(abc, def, hij)***;
%*-- on log
***"abc","def","hij"***
--*;

SASPhile
Quartz | Level 8
%cont is not defined!?
Patrick
Opal | Level 21
Hi SASPhile

Is it eventually this you're after?

%macro OUTPUT/parmbuff;

%let dsn=%scan(%bquote(&syspbuff),1,%str(%(,%)));
%let MARKET=%scan(%bquote(&syspbuff),2,%str(,%)));

%put dsn = &dsn;
%put market= &market;

%let i=3;
%let name=;
%do %while(%scan(%bquote(&syspbuff),&i,%str(,%))) ne );
%let group&i =%scan(%bquote(&syspbuff),&i,%str(,%)));
%let vgroup&i="&&group&i"N;
%if &name eq %then %let name="&&group&i";
%else %let name=&name.,"&&group&i";

%put group= &&GROUP&I;
%put VGROUP= &&VGROUP&I;

%let i=%eval(&i+1);
%end;

%put name= &name;

%mend OUTPUT;

%OUTPUT(ANTIF,ANTI-FUNGAL,ABC,DE F,HIJ)

%OUTPUT(ANTIF,ANTI-FUNGAL,ABC,DE F,HIJ, xxxx, yy yy)


HTH
Patrick Message was edited by: Patrick
SASPhile
Quartz | Level 8
if one of the parameters is like this ABC/DEF?
Patrick
Opal | Level 21
Hi SASPhile

"if one of the parameters is like this ABC/DEF?"

You're the one who knows best what strings could be passed - and probabely you need to play around a bit more with quoting and unquoting.

For the case you've given using %qscan() instead of %scan() in the %do..%while loop does the trick:
%do %while(%qscan(&syspbuff,&i,%str(,%))) ne );

HTH
Patrick
SASPhile
Quartz | Level 8
Hi,
How to insert a record?
when passing the parameters say ABC is not present in the dataset, we need to insert a record for ABC in the dataset.
Ksharp
Super User
[pre]
data class;
set sashelp.class;
run;
proc sql;
insert into class
set name='ABC',age=10;
quit;
[/pre]

Ksharp
Ksharp
Super User
How about:
[pre]

%MACRO OUTPUT(DSN,MARKET,GROUP1,GROUP2,GROUP3);
%let name=;
%let group1=%sysfunc(compress(&group1));
%let group2=%sysfunc(compress(&group2));
%let group3=%sysfunc(compress(&group3));

%DO I=1 %TO 3;
%let name=&name %str(%')&&group&i%str(%');
%END;
%let name=%sysfunc(translate(&name,%str(,),%str( )));
%put name= &name;

%mend output;
%OUTPUT(ANTIF,ANTI-FUNGAL,ABC,DE F,HIJ)

[/pre]

Ksharp

Message was edited by: Ksharp

Message was edited by: Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 12 replies
  • 1234 views
  • 0 likes
  • 5 in conversation