05-02-2012 01:38 PM
Hi, does anyone know how I can keep a variable to the back if using merge, set or proc means or proc transpose...I knwo retain keeps it in formation, but how can I always keep a new variable added to the back.. thanks
05-02-2012 01:46 PM
Your question is too general to be answered. It seems to me that you want a variable to be retained, if that is the case, in data step you can use
1. retain statement
2. sum statement
You maybe need to lay out some detailed scenario for specific answer.
05-02-2012 01:49 PM
Do you mean add it to the end of a data set, so that if your current data set has two variables
and you add a new variable Var2 your data should be
ID Var1 Var2?
05-02-2012 01:56 PM
I mean if I have this code:
proc transpose data=Test out=Test2 (drop=_name_ _label_) suffix=_Price;
by City Store;var Price;id Date;run;
It stores the Store right in the front, but how can I put the Store right at the back behind all the Prices..?
05-02-2012 02:14 PM
If I understand you correctly, you would need anther additional step (eg. data step) to get what you need.
retain blah1 blah2 .... col1 col2... STORE;
05-02-2012 02:20 PM
I have tried that and it still leaves STORE at the front.. Let me put it another way..
If I have a dataset of STORE, Var1, Var2, Var3 -- Var20 .. How Can I make it to look like this
Var1, Var2, Var3 -- Var20, STORE .. thanks
05-02-2012 02:39 PM
And if you don't want to spell out your variable names if there are many, try to use metadata:
select name into :name separated by ' ' from dictionary.columns
where libname='WORK' AND MEMNAME='TEST2' AND NAME NE 'STORE'; quit;
retain &name STORE;
05-03-2012 03:54 AM
You can always keep it as the last variable with defining it as the last statement.
05-02-2012 08:13 PM
Here is an easy way using DROP dataset option.
data want ;
set have(obs=0 drop=store) have;
You can use multiples of these zero obs datasets with combinations of keep and drop options to reorder variables.
05-02-2012 09:10 PM
Tom, your mastery of the datastep keeps amazing me!
But at the same time, I feel somewhat annoyed that the simplest way to do certain things with SAS is to use side effects. Long time ago, when I learned to program, I was warned about relying on side effects to achieve my goals. They are often underdocumented and always poorly understood by newcomers. I wonder why the theme of variable ordering keeps coming back, as I am sure it has been for years, without SAS including some feature in the language to address it.
Excuse the rant.