BookmarkSubscribeRSS Feed
ashb
Obsidian | Level 7

Good evening,

I'm trying to isolate a variable from my merged data from two specific data sets that have been merged into the data. I want to use SAS output to check the variable RIDAGEYR but i'm not sure how to do that. I'm not getting any errors, but the results I want aren't happening. Here is my code:

libname libref 'C:\Users\bamfo\Downloads';
run;
	options nodate center orientation=landscape;
run;
/*#1*/
data demo_j;
	set libref.demo_j;
run;
proc means data = work.demo_j;
TITLE 'The Contents of the DEMO_J Data Set';
run;
data bpx_j;
	set libref.bpx_j;
run;
proc means data = work.bpx_j;
TITLE 'The Contents of the BPX_J Data Set';
run;
proc contents data = work.bpx_j;
run;
data bmx_j_ge2yrs;
	set libref.bmx_j_ge2yrs;
run;
proc means data = work.bmx_j_ge2yrs;
TITLE 'The Contents of the BMX_J_GE2YRS Data Set';
run;
proc contents data = work.bmx_j_ge2yrs;
run;
data bmx_j_lt2yrs;
	set libref.bmx_j_lt2yrs;
run;
proc means data = work.bmx_j_lt2yrs;
TITLE 'The Contents of the BMX_J_LT2YRS Data Set';
run;
proc contents data = work.bmx_j_lt2yrs;
run;


/*#2*/
proc means data = work.bmx_j_ge2yrs;
TITLE 'The Contents of the BMX_J_GE2YRS Data Set';
run;
proc contents data = work.bmx_j_ge2yrs;
run;
proc sort data = work.bmx_j_ge2yrs out = work.bmx_j_ge2yrs;
	by SEQN;
run;
proc means data = work.bmx_j_lt2yrs;
TITLE 'The Contents of the BMX_J_LT2YRS Data Set';
run;
proc contents data = work.bmx_j_lt2yrs;
run;
proc sort data = work.bmx_j_lt2yrs out = work.bmx_j_lt2yrs;
	by SEQN;
run;
data all;
	set work.demo_j work.bpx_j work.bmx_j_ge2yrs work.bmx_j_lt2yrs;
	by SEQN;
run;
proc contents data = work.all;
TITLE 'The Contents of All Specified Data Sets';
run;
data all;
	merge work.demo_j work.bpx_j work.bmx_j_ge2yrs work.bmx_j_lt2yrs;
	by SEQN;
run;
proc contents data = work.all;
TITLE 'The Contents of All Specified Data Sets';
run;
/*#3*/
data all;
	merge work.demo_j (in=a) work.bpx_j(in=b) work.bmx_j_ge2yrs(in=d) work.bmx_j_lt2yrs(in=c);
	by SEQN;
	demo=a;
	bp=b;
	bodymeasure=(c=1 or d=1);
run;
proc contents data =work.all;
TITLE 'The Contents of All Specified Data Sets for #3';
run;
proc print data = work.all;
run;
proc freq data = work.all;
	tables demo bp bodymeasure;
run;
/*#4*/
data all;
	merge work.demo_j (in=a) work.bpx_j(in=b) work.bmx_j_ge2yrs(in=d) work.bmx_j_lt2yrs(in=c);
	by SEQN;
	demo=a;
	bp=b;
	bodymeasure=(c=1 or d=1);
	demobpbm=a+b+c+d;
run;
proc freq data = work.all;
	tables demo bp bodymeasure demobpbm;
run;

What should I do? Thanks in advance

 

2 REPLIES 2
Kurt_Bremser
Super User

Is it possible to get those datasets from somewhere?

If not, would you please provide examples in usable form (data steps with datalines), so we have something to develop and test code?

Tom
Super User Tom
Super User

I am not sure what your question is.  If you want to do something with just that variable then include appropriate code to do that.  Like a VAR statement in PROC MEANS or a TABLES statement in PROC FREQ.

proc means data= libref.demo_j;
  var RIDAGEYR ;
run;
proc freq data= libref.demo_j;
  tables RIDAGEYR ;
run;

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 886 views
  • 0 likes
  • 3 in conversation