BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10
data have;
length
  dept $25
  month_ 4
  count_ 8
  current 8
;
input dept month_ :monyy5. count_ current;
format month_ yymmd7.;
datalines;
Atlantic JAN20 1 1 
Atlantic JAN20 1 0 
Central FEB20 1 1  
Central APR20 1 1   
Central MAR20 1 0 
Pacific APR20 1 0   
Pacific FEB20 1 1
;
run;

PROC TRANSPOSE data=have OUT=have_2 let;
BY dept;
ID month_;
VAR  count_   /*'WAIVED FEE VOLUME'n*/;
RUN;

When the proc transpose runs, it produces the following

dept _NAME_ 2020-01 2020-02 2020-04 2020-03
Atlantic count_ 1      
Central count_   1 1 1
Pacific count_   1 1  

How can I order the for references to Month in ascending order.  In this case the 2020-04 should be last.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

No. You need change it after proc transpose.

 

 

data have;
length
  dept $25
  month_ 4
  count_ 8
  current 8
;
input dept month_ :monyy5. count_ current;
format month_ yymmd7.;
datalines;
Atlantic JAN20 1 1 
Atlantic JAN20 1 0 
Central FEB20 1 1  
Central APR20 1 1   
Central MAR20 1 0 
Pacific APR20 1 0   
Pacific FEB20 1 1
;
run;

options validvarname=any;

PROC TRANSPOSE data=have OUT=have_2 let;
BY dept;
ID month_;
VAR  count_   /*'WAIVED FEE VOLUME'n*/;
RUN;

proc sql noprint;
select distinct nliteral(put(month_,yymmd7.)) into : monthes separated by ' ' from have ;
quit;
data want;
 retain dept &monthes.;
set have_2;
run;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

In reporting procedures, the order can be determined from the values (with options like ORDER=INTERNAL). TRANSPOSE sets the column names in the order the ID values are encountered, because in datasets column order is irrelevant (columns are found by name, not position).

What do you intend to do with the wide data?

ballardw
Super User

Are you sure that you actually need a transposed data set like that? What are you doing with it?

 

 

Q1983
Lapis Lazuli | Level 10

I need to show the numeric month reference in ascending order as shown above.  I was given the idea to use order=internal in my proc report so I will try that

Ksharp
Super User

No. You need change it after proc transpose.

 

 

data have;
length
  dept $25
  month_ 4
  count_ 8
  current 8
;
input dept month_ :monyy5. count_ current;
format month_ yymmd7.;
datalines;
Atlantic JAN20 1 1 
Atlantic JAN20 1 0 
Central FEB20 1 1  
Central APR20 1 1   
Central MAR20 1 0 
Pacific APR20 1 0   
Pacific FEB20 1 1
;
run;

options validvarname=any;

PROC TRANSPOSE data=have OUT=have_2 let;
BY dept;
ID month_;
VAR  count_   /*'WAIVED FEE VOLUME'n*/;
RUN;

proc sql noprint;
select distinct nliteral(put(month_,yymmd7.)) into : monthes separated by ' ' from have ;
quit;
data want;
 retain dept &monthes.;
set have_2;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 430 views
  • 1 like
  • 4 in conversation