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/
;
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.)
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.)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.