BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I would like to combine two datasets, HAVE and Weekcode.  I would like to use MIN and MAX numbers in the weekcode column to set the "WANT" dataset range. Please help.

data HAVE;  
	Format Weekcode 4.0 Test 3.0 Pos 3.0 Lab 4.0; 
	infile datalines delimiter='/'; 
	input Weekcode Test Pos Lab;  
	datalines;                     
2102/ 8/ 3/ 256/
2103/ 3/ 1/ 619/
2106/ 5/ 2/ 2066/
2107/ 3/ 0/ 256/
2110/ 7/ 6/ 619/
;  

data weekcode;  
	Format Weekcode 4.0; 
	infile datalines delimiter='/'; 
	input Weekcode;  
	datalines;                     
2009/
2100/
2101/ 
2102/
2103/ 
2104/
2105/ 
2106/ 
2107/ 
2108/ 
2109/ 
2110/ 
2111/ 
2112/ 
2113/ 
2114/ 
2115/ 
;  

data WANT;  
	Format Weekcode 4.0 Test 3.0 Pos 3.0 Lab 4.0; 
	infile datalines delimiter='/'; 
	input Weekcode Test Pos Lab;  
	datalines;                     
2102/ 8/ 3/ 256/
2103/ 3/ 1/ 619/
2104/ 0/ 0/ 0/
2105/ 0/ 0/ 0/
2106/ 5/ 2/ 2066/
2107/ 3/ 0/ 256/
2108/ 0/ 0/ 0/
2109/ 0/ 0/ 0/
2110/ 7/ 6/ 619/
;  

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Since Weekcode appears in both your Have and Weekcode data sets which dataset is to be used to generate the Min and Max you are thinking of?

 

I might guess :

proc sql noprint;
   select min(weekcode), max(weekcode) into :minweek, :maxweek
   from have
   ;
quit;

data want; 
  merge have weekcode (where=(&minweek. le weekcode le &maxweek.));
  by weekcode;
run;

(Trivial to add the 0 instead of missing if actually desired. I'm cautious about doing such though.)

View solution in original post

2 REPLIES 2
ballardw
Super User

Since Weekcode appears in both your Have and Weekcode data sets which dataset is to be used to generate the Min and Max you are thinking of?

 

I might guess :

proc sql noprint;
   select min(weekcode), max(weekcode) into :minweek, :maxweek
   from have
   ;
quit;

data want; 
  merge have weekcode (where=(&minweek. le weekcode le &maxweek.));
  by weekcode;
run;

(Trivial to add the 0 instead of missing if actually desired. I'm cautious about doing such though.)

ybz12003
Rhodochrosite | Level 12
That works!

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!

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
  • 2 replies
  • 165 views
  • 2 likes
  • 2 in conversation