BookmarkSubscribeRSS Feed
swimmer
Calcite | Level 5

Hi,

I have a dataset with 2 observations. I want to write them to a .csv file with the second observation first and the first observation second. E.g. my data looks like

var1   var2   var3   var4

b1     b2     b3      b4

a1    a2      a3      a4

I want my .csv looks like

a1,a2,a3,a4

b1,b2,b3,b4

I tried 'put' statement with _ALL_ instead of listing the variable names explicitly because there are thousands of variables, it writes 'var1=xxxxx   var2=xxxxx' which I don't like. I only want the values to be written in the .csv file.

Thank you very much for your help.

1 REPLY 1
ballardw
Super User

I would sort the data so that it is in the order you want and then try proc export.

If you want to reverse the order of the data set;

data want;

     set have;

     order= _n_;

run;

proc sort data=want out=sorted(drop=order); by descenting order; run;

then export to csv.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1 reply
  • 745 views
  • 0 likes
  • 2 in conversation