Hi all,
I have a question about data management in SAS, and I wonder if anyone can help me.
I have an extremely large dataset. One column of the data represents data entered before the year 2005. Another column of data represents data entered after the year 2005. It looks like following:
ColumnA | ColumnB |
---|---|
. | 7 |
. | 9 |
. | 6 |
. | 5 |
. | 3 |
3 | . |
4 | . |
5 | . |
8 | . |
( . represents missing data)
If I want to combine two columns into one (let's name it columnC, is there a way to do so in SAS?)
Thank you very much for your help!
Chester
If the missing values are irrelevant, you might be able to use something like:
data have;
input columna columnb;
cards;
. 7
. 9
. 6
. 5
. 3
3 .
4 .
5 .
8 .
;
data want;
set have (keep=columnb rename=(columnb=columnc)
where=(not missing(columnc)))
have (keep=columna rename=(columna=columnc)
where=(not missing(columnc)));
run;
If the missing values are irrelevant, you might be able to use something like:
data have;
input columna columnb;
cards;
. 7
. 9
. 6
. 5
. 3
3 .
4 .
5 .
8 .
;
data want;
set have (keep=columnb rename=(columnb=columnc)
where=(not missing(columnc)))
have (keep=columna rename=(columna=columnc)
where=(not missing(columnc)));
run;
Hi ... another idea ...
data have;
input columna columnb;
cards;
. 7
. 9
. 6
. 5
. 3
3 .
4 .
5 .
8 .
;
run;
data want;
set have;
columnc = coalesce(of col:) ;
keep columnc;
run;
Thanks for all your help!
I am new to SAS and I wonder if I can ask you another question about proc content? I am trying to ask SAS to list the variables with descriptions in a dataset but SAS keeps showing the variables in alphabetical orders. Is it possible to ask SAS to list the variables in the order they are in the dataset?
The syntax that I used is as follow:
proc content data=work.datafile;
run;
Thank you very much again!
Chester
Had read somewhere that in proc contents the VARNUM variable give you the position of the variable. Cannot confirm this right now so please check it once.
VARNUM option provides the "logical" order
The internal storage order will often be different
The "logical" order is the order in which the variables are "discovered" by the compiler
I think you want the order=varnum option. The options are described in the following link:
http://support.sas.com/community/newsletters/news/techtips/OrderOption.html
Thanks for being helpful!
Chester
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 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.