data months;
array months(12) $ jan -- dec;
run;
1. How to create months January to December
Better to keep data in a long format and work with it that way.
If you want a report, use PROC REPORT on the long format data. PROC REPORT can produce columns with whatever names you want from the long format data. We can provide examples.
Not clear what you want to achieve. Please post data in usable form and show the expected output.
There is no real shortcut like the posted pseudo code. You have to spell them out.
data test;
array month{*} January February March April May June July August September October November December;
run;
You need to type all the twelve month names.
jan --dec or January -- December won't work.
You will make your coding a lot easier if you name your months like this:
data months;
array months(12) $ month1 - month12;
do i = 1 to 12;
year_array + months(i);
run;
year_sum = sum(of month1 - month12);
run;
You can always label the month variables as Jan, Feb etc.
Do not keep data (dates) in structure (variable names). Use a long dataset layout where date values are stored as such, with a display format as needed.
A wide layout for reporting purposes can always be created easily with procedures like REPORT or TABULATE.
Hello @BrahmanandaRao
You have a lot of suggestions, but the real problem is that you want a wide data set, rather than a long data set from which you create a wide report, as both @Kurt_Bremser and I have pointed out. Working with the long data set eliminates most of the problems doing this.
Here is a simple example of how using a long data set, rather than a wide data set, still results in a wide report. The programming is simple when you do it this way. Solved: Re: format all column names that are similar - SAS Support Communities
In your example, where the wanted columns are months, SAS provides many formats so that you can make the columns in PROC REPORT have meaningful column headings (such as Jan, Feb, etc.) without you actually having to type them in yourself.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.