BookmarkSubscribeRSS Feed
pacman94
Calcite | Level 5

I have the following dataset which is sorted by SEQ because that is the order i would like to keep for the CSV output

 

proc sort data = test; by seq;run;

Group1Group 2Value1Value2Value3SEQ
Total 124161
ADESDF5122
EFEERW1183
DSFDGR1114
DFDWER5155

 

However when I proc report export to the CSV, it shows 'total' in the bottom 'seq' sorting is gone. 

 

ods csv file = 'filepath\test.csv.';

proc report data = test nowindows headline headskip;

column group1 group2 value1 value2 value3;

define group1/display = "Group 1" width =14;

define group2/display = "Group 2" width =14;

define value1 /display = "Value 1" width =14;

define value2/display = "Value 2" width =14;

define value3/display = "Value 3" width =14;

run;

3 REPLIES 3
ballardw
Super User

Since you did not provide any "order" information SAS used the default rules, which are generally going to be the formatted appearance of columns from left to right.

CSV has nothing to do with this.

Try

proc report data = test nowindows headline headskip;
   column seq group1 group2 value1 value2 value3;
   define seq / order noprint;
   define group1/display = "Group 1" width =14;
   define group2/display = "Group 2" width =14;
   define value1 /display = "Value 1" width =14;
   define value2/display = "Value 2" width =14;
   define value3/display = "Value 3" width =14;

run;
FreelanceReinh
Jade | Level 19

Hi @pacman94,

 

The advantage of using SEQ as an order variable (as suggested by @ballardw) is that you don't need to sort the dataset in advance. If it is sorted by SEQ, however, you don't need to mention SEQ in the PROC REPORT step. Since all report items are display variables, the report should reflect the order of observations in the dataset. Maybe your last PROC REPORT step didn't run properly because of the invalid equal signs after "display" (did you check the log?) and that's why in your case (seemingly) "it shows 'total' in the bottom 'seq' sorting is gone."

Cynthia_sas
Diamond | Level 26
And, in addition to @FreelanceReinhard's suggestion, keep in mind that your options such as headline, headskip and WIDTH= are ignored by ALL ODS destinations, these are LISTING only options and not relevant to ODS CSV.
Cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1005 views
  • 0 likes
  • 4 in conversation