Hello,
I am trying to name a column as the previous month, with the year if possible, but at this point just the month would be a big help.
Below is the working code I have, however, this only names the column the current month.
I've tried INTNX but to no avail.
PROC SQL;
CREATE TABLE MAP_VALIDATION AS
SELECT DISTINCT t1.'MAP_ID'n,
(COUNT(t1.MPXN)) AS %sysfunc(today(),monyy7.)
FROM ZZ_PRC_OUTPUT t1
GROUP BY t1.'MAP_ID'n;
QUIT;
Any help would be MUCH appreciated.
I highly recommend you don't. Column names are something for a programming point of view, not for a user looking at the data. As you have found, just creating the variable like that is a real pain, now imagine trying to program with that, each datastep you need to find out what variables are present, what they are called etc. It will just make all programming far more complicated and less robust. If you need the information for a report, then put this information in the Label - which is the part for free text to show what the variable contains, and give the variable a logical simple name.
I would also highly recommend not to use named literals:
t1.'MAP_ID'n,
These are really only there for the rare time that you need to access a non-standard variable name from a bad data source such as Excel. Normal programming should use SAS compliant variable names - as you will have been shown through all basic courses - to make coding far simpler, easier to read, and more robust.
Please avoid shouting code also.
data _null_;
call symputx('my',put(intnx('month',today(),1),monyy7.));
run;
proc sql; create table map_validation as select distinct t1.map_id, count(t1.mpxn) as &my. from zz_prc_output t1 group by t1.map_id; quit;
I tend to do things like that in a datastep as the syntax is easier to read than a whole stream of % and &'s.
I highly recommend you don't. Column names are something for a programming point of view, not for a user looking at the data. As you have found, just creating the variable like that is a real pain, now imagine trying to program with that, each datastep you need to find out what variables are present, what they are called etc. It will just make all programming far more complicated and less robust. If you need the information for a report, then put this information in the Label - which is the part for free text to show what the variable contains, and give the variable a logical simple name.
I would also highly recommend not to use named literals:
t1.'MAP_ID'n,
These are really only there for the rare time that you need to access a non-standard variable name from a bad data source such as Excel. Normal programming should use SAS compliant variable names - as you will have been shown through all basic courses - to make coding far simpler, easier to read, and more robust.
Please avoid shouting code also.
data _null_;
call symputx('my',put(intnx('month',today(),1),monyy7.));
run;
proc sql; create table map_validation as select distinct t1.map_id, count(t1.mpxn) as &my. from zz_prc_output t1 group by t1.map_id; quit;
I tend to do things like that in a datastep as the syntax is easier to read than a whole stream of % and &'s.
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.
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.