BookmarkSubscribeRSS Feed
Navnath
Calcite | Level 5

Hi Experts,

 

I have following data in rule column:

s_norule
1Security_type in("GSEC", "SSEC")
2Security_type = "OAS" AND Guaranteer = "Cent_govt"
3Security_type = "OAS" AND Guaranteer = "State_govt" AND Residual_maturity LE 0.5
4Security_type = "OAS" AND Guaranteer = "State_govt" AND Residual_maturity GT 0.5 LE 2
5Security_type = "OAS" AND Guaranteer = "State_govt" AND Residual_maturity GT 2

 

I want to create 5 macro variable var1 var2 . . var5 which contains

var1: Security_type in("GSEC", "SSEC")

var2: Security_type = "OAS" AND Guaranteer = "Cent_govt" 

.

.

and so on.

 

sample code is here:

%macro mymacro;
proc sql noprint;
select count(rule) into :count from MRCC_SMM.SMM_report_rules where s_no is not null;
quit;

proc sql noprint;
select rule into:var separated by '@' from MRCC_SMM.SMM_report_rules where s_no is not null;
quit;

%do i=1 %to &count;
data _null_;
call symput("var&&i.",%sysfunc(scan("&&var.", &&i., "@")));
run;


%end;
%mend;

%mymacro;

 

Please give any idea how I can do that?. Thanks In advance.

3 REPLIES 3
PaigeMiller
Diamond | Level 26
data _null_;
    set have;
    call symputx(cats('var',s_no),rule);
run;
--
Paige Miller
Tom
Super User Tom
Super User

Don't use macro code where you need regular SAS code. Remember macro processor is just there to help you generate SAS code.  For this problem you don't need any macro code at all.  Just a data step.

data _null_;
  set  MRCC_SMM.SMM_report_rules end=eof;
  where not missing(s_no);
  call symputx(cats('var',_n_),rule);
  if eof then call symputx('count',_n_);
run;
PaigeMiller
Diamond | Level 26

Another option:

 

proc sql noprint;
    select rule into :var1- from mydatasetname;
quit;
%let nvars=&sqlobs;

You don't even have to know how many &var variables will be created, SAS figures it out for you. The number created is in &SQLOBS, which I have stored for later use in &NVARS.

 

Note: if the numbers in s_no are not consecutive, this may or may not work, depending on what you do with them. The CALL SYMPUTX method that I provided earlier will work if s_no are not consecutive.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 941 views
  • 0 likes
  • 3 in conversation