Hi Everyone,
I have a large number of columns and I want to move var1 var2 var3 to the end.
Since there are many column, I dont want to list too many column in retain.
I can reorder by taking these 3 column out and SQL it back to the main file.
However, I wonder if there is any easy way to do it.
Thank you,
HHCFX
Interesting idea, so you have a condition which can never be met around the first step which creates all but the var variables in the PDV. Then add the var variables with retain, then add the data. You would have thought you could do this in proc datasets by now.
OP: Why do you need to move these? Am just thinking, if its for a report, then your better off just setting the position in the reporting procedure when you assign labels and styles etc. Combine the two saves time and maintenance. If its to follow a specific template for the data, you may be better off creating a template of what the file should look like (all formats, informats, labels etc.) in a file with no observations, then setting that with your data when needed, this way you only need to set structure in the template (one place). There is never, in programming terms a need to move columns as logical position is irrelevant.
I am working with an existing report each month and need to reorder thing around.
Thanks.
HHC
@hhchenfx wrote:
I am working with an existing report each month and need to reorder thing around.
Thanks.
HHC
Any report method in SAS has re-ordering of the columns built in.
In PROC PRINT, it's the VAR command to re-order columns. In PROC REPORT, it's the COLUMNS command to re-order columns. In PROC TABULATE, use the {I can't remember} command to re-order columns.
So don't do any programming to re-order columns, just use one of the above tools.
Thank you for your suggestion but I am not familiar with those proc.
HHC
Proc print, report, and tabulate are the standard output procedures of SAS. If you don't know those then you have more problems than just re-arranging. Each procedure has a method to arrange output in a certain way and print or not to print certain variables. Rather than wasting processor cycles and read/write cycles creating a new dataset, use the procedure options. E.g.:
proc report ...; columns ... var1 var2 var3; ... run;
@hhchenfx wrote:
Thank you for your suggestion but I am not familiar with those proc.
HHC
Then how are you doing the reporting? What PROC are you using? Or are you using a DATA step, with PUT statements?
I add that there are many powerful reporting capabilities in these PROCs, and in the long run, you will get a lot more done, and do it a lot more easily, by learning and using these PROCs. In particular, for relative simple reports, PROC PRINT is about as easy to use as can be.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: