04-18-2018 02:51 AM
Hi, I want to create a do loop to increment the values of a variable in a sas dataset.
I am writing the following code:
select Off into: Off_Var separated by ','
%do i=0 to 1;
%let Off_Mac= &Off_Var.&i;
I want to put the first value from Off_Var to Off_Mac when i=0, and put the second value of Off_Var to Off_Mac when i=1.
04-18-2018 02:56 AM
You will only get one macro variable out fo the SQL, so you need to dissect it:
%do i=0 %to 1; %let Off_Mac= %scan(&Off_Var,&i+1); %end;
(assuming there's lots of more code in the macro loop, as you always end up with the second word after the loop)
04-19-2018 02:54 AM
from the Macro Language Reference
04-18-2018 02:58 AM
PS &off_var is not an array, it is what is usually called a list macro variable.
SAS arrays only exist in data step code.
04-18-2018 04:43 AM
What is it your trying to do? Really don't see the point in this. I mean if you need to split that var into two then:
data _null_; set control_table; call symputx('off_mac1',scan(off,1,",")); call symputx('off_mac2',scan(off,2,",")); run;
But that just seems to be a waste of coding time, if you already have the data in the dataset, you can simply merge that row onto the data you need to check and check then, hence avoiding all this messy code. Providing test data in the form of a datastep and what you want to see at the end really helps clarify questions.
Need further help from the community? Please ask a new question.