BookmarkSubscribeRSS Feed
Bal23
Lapis Lazuli | Level 10

my merge statment generates missing value for the first dataset

 

plesae see the attached two datasets. the real datasets are very long with many columns.

These two datasets were generated by sas macro.

Now I want to merge these two together.

 

data first;
set first1 first2;
by _NAME_;
run;
proc print data = first;
run;

the problem is,

the data generated actually put the first one into the first one, and the second one, the values are all missing

 

sample datasets attached

 

6 REPLIES 6
Steelers_In_DC
Barite | Level 11

I just ran the following code, I'll paste my output below.  Not sure what you are looking for but if that's the output you are getting I'd check the inputs:

 

data one;
infile cards dsd;
informat name $3. _1af _1af2 8.;
input name _1af _1af2;
cards;
c1a,1083,187
;run;

data two;
infile cards dsd;
informat name $3. _2af _2f2 8.;
input name$ _2af _2f2;
cards;
c1a,1083,187
;run;

data want;
set one two;
by name;
run;

 

name _1af _1af2 _2af _2f2
c1a 1083 187    
c1a     1083 187
Bal23
Lapis Lazuli | Level 10

Thanks. Now I understand why you are confused. No wonder why SAS is confused too.

 

 

i want to have a table

name  _af1  _af2
c1a       1086  187
c2a      1083   1

i need them to be vertically added, not horizontally appended
i hope it is clear enough

 

name_1af_1af2_2af_2f2
c1a1083187  
c1a  10831
Steelers_In_DC
Barite | Level 11

You need to change the variables in the second dataset:

 

data want;
set one

      two(rename=(_2af=_1af _2f2=_1af2));
by name;
run;

Bal23
Lapis Lazuli | Level 10

Thank you very  much. This works.

The problem is my original two tables are generated by sas macro. It is time consuming to change name one by one.

Would you please provide sas macro code?

 

ballardw
Super User

If you are generating the names in a macro then that would be the place to execute this code while the macro knows what they are.

Steelers_In_DC
Barite | Level 11

I agree, manipulate this within the original macro to get the desired variable names. 

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 859 views
  • 0 likes
  • 3 in conversation