BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data months;
array months(12) $ jan -- dec;
run;

1. How to create months January to December  

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
andreas_lds
Jade | Level 19

Not clear what you want to achieve. Please post data in usable form and show the expected output.

PeterClemmensen
Tourmaline | Level 20

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;
Sajid01
Meteorite | Level 14

You need to type all the twelve month names.
jan --dec or January -- December  won't work.

SASKiwi
PROC Star

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.

Kurt_Bremser
Super User

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 7 replies
  • 2001 views
  • 0 likes
  • 7 in conversation