re-order SAS variables

Reply
N/A
Posts: 0

re-order SAS variables

In one SAS dataset, there's 3 variavbles, v1, v2, v3. Now I want to re-order these to v3, v2, v1.

One solution in DATA STEP is;

******************;
data test2;
retain v3 v2 v1;
set test;
******************;

But if retain statement has > 960 characters? SAS prompts an error message saying it can't process more than 960 char. Any solution to that?

Or I have to separate RETAIN statement into >=2 lines instead?
Or there's an ultimate way to do that Smiley Happy

Thanks!
David
SAS Super FREQ
Posts: 8,815

Re: re-order SAS variables

It seems you are running into this issue:
http://support.sas.com/techsup/unotes/SN/010/010199.html

SAS ignores white space in your statements, so this statement on 3 separate lines:
[pre]
retain v3
v2
v1;
[/pre]
Would be the equivalent of
[pre]
retain v3 v2 v1;
[/pre]

cynthia
Contributor
Posts: 49

Re: re-order SAS variables

The other alternative (and the one I prefer) is to use PROC SQL.

PROC SQL;
CREATE TABLE xxx AS
SELECT v3, v2, v1
FROM xxx;
QUIT;
SAS Super FREQ
Posts: 8,815

Re: re-order SAS variables

True. But in retrospect, I really don't understand the need to reorder the variables in the existing dataset.

Most reporting procedures give you a way to control the order on the report row and when you initially read the data INTO SAS form, your LENGTH statement or the order of the variables on your INPUT statement will get the variables in "order".

But I suppose if you have a boatload of variables and just want to use the default procedures without using a VAR or COLUMN statement than any of these methods is OK -- as described in these references:
http://support.sas.com/techsup/unotes/SN/008/008395.html
http://paulchoate61.googlepages.com/DPR-Choate.pdf
http://www8.sas.com/scholars/05/PREVIOUS/2001_200.4/2004_MOR/Proceed/_2002/Posters/PS12.pdf

cynthia
Contributor
Posts: 49

Re: re-order SAS variables

It's probably to do with a customer requirement. Many of our clients have a variable order preference so that when someone is browsing the data set (either FSV or Viewtable) then the key variables (i.e. subject ID) are always to the left of the screen. Makes it much easier than having to manually shift the variables around.
Valued Guide
Posts: 2,177

Re: re-order SAS variables

where you use SAS/FSP FSView windows to review data, you can use the formula command to retrieve a previously stored customized layout, which will have retained your preferred column order and formats. Once opened, the formula will be updated with any new customization (including "the current columns in view") as the window is closed. A formula can be created by issuing command "save formula".

Viewtable layout customization can be saved. A poster to SAS-L shared his technique --- his method uses SAS/AF processes he created. I can use his processes without requiring SAS/AF to be licensed.

Both these methods of working with previously stored layout customization can be integrated with the SAS Explorer ~ becoming the default behaviour or just optional.

I particularly like being able to customize the "form view" that SAS/FSP, FSbrowse windows allow. Again, it is the customization available through SAS Explorer, that makes re-use of these form layouts, so extremely convenient.

Peter C
Ask a Question
Discussion stats
  • 5 replies
  • 542 views
  • 0 likes
  • 4 in conversation