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

I hope this is an easy question for sasperts.

I am updating the previous 10 year trend data with new data, to make a new 10 year trend data set.

old data set is indicators2008_2017

adding in data for 2018, so for the new 10 year trend data set, i want the data set to be indicators2009_2018

 

Is this right?

**** edit Year ******************** ;
%let Year = 2018 ;
/* these two lines are to identify the previous 10 year data set, that ends with the year -before- "year" and begins with year - 10.
For example, when updating with 2018 data, the previous data set was indicators2008_2017 */
%let oldendyr=%eval(&Year-1);
%let oldstartyr=%eval(&Year-10);

* AND need the first year of the new 10 year data set, which would be year -9 ;
%let newstartyr=%eval(&Year-9);

 

 

Then next, I'm trying to bring together the data for the current year with the data with the previous data set. I know this isn't right because I get errors.


data indicators&newstartyr_&Year;
set sasout.indicators&oldstartyr_&oldendyr
indicators&Year;
run;

 

 

Here is some output


2836 data indicators&newstartyr_&Year;

(next three lines below under the & symbol)

-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;,
_DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

 

Help appreciated.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

So you ran this?

%let Year = 2018 ;
%let oldendyr=%eval(&Year-1);
%let oldstartyr=%eval(&Year-10);
%let newstartyr=%eval(&Year-9);
data indicators&newstartyr_&Year;
  set sasout.indicators&oldstartyr_&oldendyr indicators&Year;
run;

If so you are referencing two macro variables named NEWSTARTYR_ and OLDSTARTYR_ that you never defined.

 

You must use a period to let the macro processor know where the macro variable name ends when you have appended some other characters that could be part of the name.

data indicators&newstartyr._&Year;
  set sasout.indicators&oldstartyr._&oldendyr indicators&Year;
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

So you ran this?

%let Year = 2018 ;
%let oldendyr=%eval(&Year-1);
%let oldstartyr=%eval(&Year-10);
%let newstartyr=%eval(&Year-9);
data indicators&newstartyr_&Year;
  set sasout.indicators&oldstartyr_&oldendyr indicators&Year;
run;

If so you are referencing two macro variables named NEWSTARTYR_ and OLDSTARTYR_ that you never defined.

 

You must use a period to let the macro processor know where the macro variable name ends when you have appended some other characters that could be part of the name.

data indicators&newstartyr._&Year;
  set sasout.indicators&oldstartyr._&oldendyr indicators&Year;
run;

 

geneshackman
Pyrite | Level 9
Thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 708 views
  • 2 likes
  • 2 in conversation