the data set name is two_clean.
I have column names like 201808 201901 201908 202001
column Name 201808 201901 201908 202001
Row 1 _1_5_4_P _1_5_4_P _1_5_4_P _1_5_4_P
Here is my code:
%MACRO pairs(pair1, pair2, pair3, pair4);
DATA year&pair1;
SET two_clean;
WHERE %tslit(&pair2) NE '';
IF &pair2 NE '' AND &pair3='' THEN &pair3="Did not return";
KEEP ID &pair2 &pair3;
RUN;
%mend pairs;
%pairs(1,&term3,&term2,&term3);
Error Message:-
SYMBOLGEN: Macro variable PAIR2 resolves to 202208
SYMBOLGEN: Macro variable PAIR3 resolves to 202301
SYMBOLGEN: Macro variable PAIR3 resolves to 202301
NOTE: Line generated by the macro variable "PAIR3".
53 202301
______
180
MPRINT(PAIRS): IF 202208 NE '' AND 202301='' THEN 202301="Did not return";
SYMBOLGEN: Macro variable PAIR2 resolves to 202208
SYMBOLGEN: Macro variable PAIR3 resolves to 202301
NOTE 138-205: Line generated by the macro variable "PAIR2".
53 202208
______
22
ERROR 180-322: Statement is not valid or it is used out of proper order.
ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
NOTE: Line generated by the macro variable "PAIR2".
53 202208
______
200
ERROR 200-322: The symbol is not recognized and will be ignored.
MPRINT(PAIRS): KEEP ID 202208 202301;
MPRINT(PAIRS): RUN;
If you insist on using non-standard SAS column names then to refer to them in code you have to enclose them in quotes, immediately followed by the letter "n":
'202308'n or if it is resolving a macro variable "&MyVar"n. Personally I find the cure worse than the disease so I never use non-standard names.
How did you get a variable name like 202208? That's not a usual name in SAS. Perhaps you could run a PROC CONTENTS on your data set and confirm what is in there.
If you insist on using non-standard SAS column names then to refer to them in code you have to enclose them in quotes, immediately followed by the letter "n":
'202308'n or if it is resolving a macro variable "&MyVar"n. Personally I find the cure worse than the disease so I never use non-standard names.
The macro variables TERM2 and TERM3 have the wrong types of values for how you are trying to use them. You are using them as variable names, but the strings you have in them are just digit strings, so to SAS code they look like numbers.
You don't show where they are getting there values from, but you should change them to :
%let term3 = "202208"n;
%let term2 = "202301"n;
You have two issues here:
Do this:
proc transpose data=two_clean out=long1 (rename=(col1=value));
by /* use variable(s) which identify each row/observation, sort first if necessary */;
var '201808'n--'202308'n;
run;
data long;
set long1;
month = input(_name_,yymmn6.);
format month yymmn6.;
drop _name_;
run;
You can now use all date-related functions/tools on the data to help with your analysis.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.