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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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