BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Akhila1
Fluorite | Level 6

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;

 

Akhila1_0-1706742767564.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.

Akhila1
Fluorite | Level 6

Akhila1_0-1706742820861.png

 

SASKiwi
PROC Star

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.

Tom
Super User Tom
Super User

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

You have two issues here:

  1. usage of VALIDVARNAME=ANY, combined with the use of PROC IMPORT; this leads to non-standard names
  2. hiding data (dates) in structure (variable names)

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.

SAS Innovate 2025: Register Now

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!

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
  • 5 replies
  • 990 views
  • 1 like
  • 5 in conversation