BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
satish78652
Fluorite | Level 6

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Or like this?


data _null_;
  set HAVE;
  PREV=lag(VAR);
  if PREV ne ' ' then 
  call execute('%test(start='||PREV||',stop='||VAR||');');
run;

 

View solution in original post

8 REPLIES 8
Reeza
Super User

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. 

ChrisNZ
Tourmaline | Level 20

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

 

 

ChrisNZ
Tourmaline | Level 20

Or like this?


data _null_;
  set HAVE;
  PREV=lag(VAR);
  if PREV ne ' ' then 
  call execute('%test(start='||PREV||',stop='||VAR||');');
run;

 

satish78652
Fluorite | Level 6

The programme provided is working only for numeric variables. Can you please modify it to work for character variable as well?

satish78652
Fluorite | Level 6

the programe is not working for the variables like name, address and language.

satish78652
Fluorite | Level 6

Thank you for your help Chriz. Now i got it.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1727 views
  • 3 likes
  • 3 in conversation