Help using Base SAS procedures

A Question Regarding Data Management

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

A Question Regarding Data Management

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:

ColumnAColumnB
.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


Accepted Solutions
Solution
‎08-02-2011 09:51 AM
PROC Star
Posts: 7,492

A Question Regarding Data Management

Posted in reply to PsycResearcher

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;

View solution in original post


All Replies
Solution
‎08-02-2011 09:51 AM
PROC Star
Posts: 7,492

A Question Regarding Data Management

Posted in reply to PsycResearcher

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;

Valued Guide
Posts: 765

Re: A Question Regarding Data Management

Posted in reply to PsycResearcher

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 colSmiley Happy ;

keep columnc;

run;

Occasional Contributor
Posts: 14

Re: A Question Regarding Data Management

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

Regular Contributor
Regular Contributor
Posts: 166

A Question Regarding Data Management

Posted in reply to PsycResearcher

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.

Valued Guide
Posts: 2,177

A Question Regarding Data Management

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

PROC Star
Posts: 7,492

Re: A Question Regarding Data Management

Posted in reply to PsycResearcher

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

Occasional Contributor
Posts: 14

A Question Regarding Data Management

Thanks for being helpful!

Chester

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 147 views
  • 6 likes
  • 5 in conversation