03-30-2015 12:32 PM
I am creating a report every month and 2 of my columns are labelled "Current Months Rate" and "Previous Months Rate" I was wondering if there was an easy way to actually display the date or even the Year and Month in place of "Current Months Rate" or "Previous Months Rate". So instead of "Current Months Rate" I would like the column to be labelled 03/01/2015 or 2015_03. And I would need these columns to be relabelled automatically every month.
Any help would be much appreciated.
03-30-2015 12:39 PM
Is this from a procedure, if so which one (different options may be available). Is there a variable used to split the data into the two columns?
Would a solution based on the date the program is run be sufficient?
If you are starting with date values you may have a very easy solution but without knowing what your data looks like its not obvious if we should pursue that approach.
03-30-2015 12:45 PM
I am joining several tables to get this report. I am using a master table to pull my last months numbers, using max date. I am running my query again to get current months rate. I am adding a Case function to compare the 2 columns. After I run my compare, I want to change the labels to dates if possible.
03-30-2015 03:53 PM
I would keep my data in a long format until the 'final' dataset - which I don't recommend storing this way. When you need the data set this way you can use proc transpose to flip it with the IDLABEL option to ensure that the date is the label.
03-30-2015 01:26 PM
The SAS LABEL will need to be resolved with a double-quoted macro variable reference. And you can use PROC SQL to select the SAS variable's data-value(s) into a SAS macro variable (for example, call it macro variable PERIOD) in a step ahead of the DATA / PROC step that sets the SAS statement, for illustration:
LABEL <myvar> = "Current Period (&period)";
Check the SAS PROC SQL DOC and SAS.COM resources for using INTO with SELECT <varname> -- to create the SAS macro variable needed to resolve the various labels accurately.
Note that this can also be done in a preceding DATA step that reads the input file, with SET <filename> ( KEEP=<myvar>) END=EOF; and then upon IF EOF THEN DO; * SAS code; END; to issue CALL SYMPUT with a formatted SAS date variable to resolve the SAS macro variable.
03-30-2015 03:20 PM
drop table test;quit;
label region = "&daterun.";
proc print data=test(obs=9) label; run;
03-31-2015 09:06 AM
A common way to automatically relabel every month is to use the INTNX function.
To illustrate, assume you can calculate the max date as being some day during April 2015. Assume further that this means the "Current month" is March 2015 and the "Previous month" is February 2015. (If the assumptions are incorrect, you can adjust the code pretty easily.)
Here is some code that captures the months/years as macro variables.
* max_date is somehow previously calculated and brought in here;
call symputx('current_my', put( intnx('month', max_date, -1), mmddyys10.));
call symputx('prior_my', put( intnx('month', max_date, -2), mmddyys10.));
You can then use these macro variables as part of the labels when printing.
label current_month = "¤t_my";
You will have the obligation to run the program during the correct month, otherwise you would need to change the code to get the proper column headings.