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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Dani_Gor
SAS Employee

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...

View solution in original post

7 REPLIES 7
PhilC
Rhodochrosite | Level 12

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;
ballardw
Super User

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?

tedway
Obsidian | Level 7

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.

 

 

Dani_Gor
SAS Employee

Are you expecting a result like this one?

 

Test.PNG

 

 

 

Dani_Gor
SAS Employee

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...

tedway
Obsidian | Level 7
That works great. Thank!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 1463 views
  • 2 likes
  • 4 in conversation