Hi Mate,
I need help from you guys. Let me explain you my problem firtst. I have created a single variable dataset (All the observation of this dataset are variables for my other programming.). Now i need to use the observations in a sequence like 1st observation and 2nd observation will be considered as Macro variables "START" and "STOP" in another programe and once the macro finishes forst ittration then 2nd observation should be "START" and 3rd observation should be "STOP" variable. Like this, the entire observations need to be used as derived Macro variables in another programme.
Example:
Dataset_1
obs Title
01 Name
02 age
03 sex
04 address
05 language
Programme:
%macro test (Start= , Stop= );
if var1= &START then Seq+1;
if var1= &STOP then seq+1;
if seq=1 or var1= &STOP;
%mend test;
Please provide me a solution to use the observation of dataset_1 as macro variables in the above programe in the above specified sequence.
Thanks
Or like this?
data _null_;
set HAVE;
PREV=lag(VAR);
if PREV ne ' ' then
call execute('%test(start='||PREV||',stop='||VAR||');');
run;
Look at CALL EXECUTE if I understand your question correctly. It's ambiguous.
The example in the documentation shows how a dataset can drive a macro.
Like this?
data HAVE;
input VAR $;
cards;
Name
age
sex
address
language
run;
proc sql noprint;
select VAR into :varlist separated by ' ' from HAVE;
quit;
%macro test(start=, stop=);
%put Replace with actual code &=start &=stop;
%mend;
%macro loop;
%local i;
%do i=1 %to &sqlobs.-1;
%test(START=%scan(&varlist, &i),STOP=%scan(&varlist, &i+1));
%end;
%mend;
%loop;
Replace with actual code START=Name STOP=age
Replace with actual code START=age STOP=sex
Replace with actual code START=sex STOP=address
Replace with actual code START=address STOP=language
Or like this?
data _null_;
set HAVE;
PREV=lag(VAR);
if PREV ne ' ' then
call execute('%test(start='||PREV||',stop='||VAR||');');
run;
The programme provided is working only for numeric variables. Can you please modify it to work for character variable as well?
the programe is not working for the variables like name, address and language.
Thank you for your help Chriz. Now i got it.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.