BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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 🙂

Thanks!
David
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
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
LawrenceHW
Quartz | Level 8
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;
Cynthia_sas
SAS Super FREQ
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
LawrenceHW
Quartz | Level 8
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.
Peter_C
Rhodochrosite | Level 12
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 5 replies
  • 1570 views
  • 0 likes
  • 4 in conversation