I have a variable that is a list of years in character format, and I want to save the value in a data set for future reference.
Here's what I tried:
%let prior_years = ("1988","1999","2000");
data test;
test = &prior_term;
run;And I get this error.
30 ("202040","99999","89898")
_
388
200
ERROR 388-185: Expecting an arithmetic operator.
ERROR 200-322: The symbol is not recognized and will be ignored.I could do this and it works, but I don't want to change the format for the prior_years variable:
%let prior_years = (1988,2000);
data test;
test = "&prior_years";
run;
I think this code may solve your problem:
%let prior_years = ("1988","1999","2000");
%let list=%tslit(&prior_years);
%put &=list;
data test;
test = &list;
run;
documentation at this link: https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lebaseutilref&docsetTa...
What's your previous experience with programming? I am curious.
you can do this the "wide" way or the "narrow" way.
the wide:
data want_wide;
year1 =1988;
year2 =1999;
year3 =2000;
run;
the narrow:
data want_narrow;
year =1988; output;
year =1999; output;
year =2000; output;
run;
A variable that has a list of items would typically look like:
data example;
var = "1998, 1999, 2011";
run;
Quotes inside values are typically a very bad idea.
So, why do you have quotes and a delimiter in the value?.
And your example code creates one macro variable an then uses a different one.
%let prior_years = ("1988","1999","2000");
data test;
test = &prior_term;
run;
it would make, slightly, more sense to do.
%let prior_years =1988,1999,2000; data test; test = "&prior_years"; run;
The question is why is a macro variable involved at all?
I'm using prior_years as the criteria in proc sql and this format has always worked:
prior_years = ("1988","1999","2000");
I'm just trying to store the current value of prior_years in a data set so that I have it for future reference. I also capture the current date and other stuff so that I can look back at it and see what values I used.
Are you expecting a result like this one?
Yes.
I think this code may solve your problem:
%let prior_years = ("1988","1999","2000");
%let list=%tslit(&prior_years);
%put &=list;
data test;
test = &list;
run;
documentation at this link: https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lebaseutilref&docsetTa...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.