BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sassy-Grrl
Calcite | Level 5

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Sassy-Grrl
Calcite | Level 5
Wow, thank you so much for that quick reply.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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