BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PsycResearcher
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

7 REPLIES 7
art297
Opal | Level 21

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;

MikeZdeb
Rhodochrosite | Level 12

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;

PsycResearcher
Calcite | Level 5

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

NN
Quartz | Level 8 NN
Quartz | Level 8

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.

Peter_C
Rhodochrosite | Level 12

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

art297
Opal | Level 21

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

PsycResearcher
Calcite | Level 5

Thanks for being helpful!

Chester

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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