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