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

Hello,

 

I have two tables year2015, year2016, but how can I get the third table ds1 based on the two by coding sas? Thanks!

 


data year2015;
input year $ resp ;
datalines;
null 0.35
s_300 0.55
s_640 0.65
s_670 0.75
s_700 0.47
s_730 0.58
s_760 0.69
;run;
data year2016;
input year $ resp ;
datalines;
null 0.45
s_300 0.65
s_640 0.42
s_670 0.35
s_700 0.83
s_730 0.48
s_760 0.69
;run;

 

data ds1;
input year $ mid $ resp exp rev;
datalines;
null d_2016 0.45 0.45 0.35
null d_2015 0.35 0.45 0.35
s_300 d_2016 0.65 0.65 0.55
s_300 d_2015 0.55 0.65 0.55
s_640 d_2016 0.42 0.42 0.65
s_640 d_2015 0.65 0.42 0.65
s_670 d_2016 0.35 0.35 0.75
s_670 d_2015 0.75 0.35 0.75
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.47 0.83 0.47
s_730 d_2016 0.48 0.48 0.58
s_730 d_2015 0.58 0.48 0.58
s_760 d_2016 0.67 0.67 0.69
s_760 d_2015 0.69 0.67 0.69
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
Opal | Level 21

OK, let's ignore REV and EXP since you will be hard-coding them.  Sort the data sets first, if they are not already sorted:

 

proc sort data=year2015;

by year;

run;

proc sort data=year2016;

by year;

run;

 

Then combine them:

 

data want;

set year2016 (in=from2016) year2015 (in=from2015);

by year;

if from2016 then mid='d_2016';

else mid='d_2015';

run;

View solution in original post

5 REPLIES 5
Reeza
Super User

Ok...what's the relationship between the tables...

Astounding
Opal | Level 21

That depends.  Where do EXP and REV come from if they're not part of the incoming data sets?

zhangda
Fluorite | Level 6
there is no EXP and REV, I have to hard code it.
ballardw
Super User

And another way to get something similar. Mid has the data set names here but could be modified with string functions to get D_XXXX if that format is explicitly required.

 

data want;
   set year2015 year2016 indsname=name;
   mid=name;
run;

proc sort data=want; 
   by year mid;
run;
Astounding
Opal | Level 21

OK, let's ignore REV and EXP since you will be hard-coding them.  Sort the data sets first, if they are not already sorted:

 

proc sort data=year2015;

by year;

run;

proc sort data=year2016;

by year;

run;

 

Then combine them:

 

data want;

set year2016 (in=from2016) year2015 (in=from2015);

by year;

if from2016 then mid='d_2016';

else mid='d_2015';

run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 878 views
  • 1 like
  • 4 in conversation