G'day!
For the file below, for the variable GSS, if we're looking to find a facility that has the number 6 between the ranges for
i.e, for GSS=-8 and GSS=1-9, etc, we want to keep the field 'code' and 'GSS' where the span includes a 6,
how would you do that.
For example, where
facilitycode=01100170112607 and GSS = 0-12
since GSS has a range between 0,1,2,3,4,5,6,7,8,9,10,11 and 12, there is a 6, how do we identify this facility as one we want to keep because it has a 6 in the range into a separate dataset?
We need to do this for all the observations in the dataset.
Would you separate out GSS in the example above 2 variables: GSLow=0 GSHigh=12 and then ask SAS to determine if there is a 6 in that span?
Any help you can give will be much appreciated!
Thank you!
/* --------------------------------------------------------------------
-------------------------------------------------------------------- */
DATA WORK.'Sch gss'n;
LENGTH
F1 $ 14
F2 $ 5 ;
FORMAT
F1 $CHAR14.
F2 $CHAR5. ;
INFORMAT
F1 $CHAR14.
F2 $CHAR5. ;
INFILE DATALINES4
DLM='7F'x
MISSOVER
DSD ;
INPUT
F1 : $CHAR14.
F2 : $CHAR5. ;
DATALINES4;
FaclityCodeGSS
011001701126070-12
011001701239680-8
011001701241720-8
011001701255670-8
011001701294036-8
016115060904350-5
016115060904680-5
;;;;
Want:
The first 5 lines of the dataset above that have 6 in the span of GSS
DATA WORK.test;
LENGTH
F1 $ 14
F2 $ 5 ;
FORMAT
F1 $CHAR14.
F2 $CHAR5. ;
INFORMAT
F1 $CHAR14.
F2 $CHAR5. ;
INPUT
F1 : $CHAR14.
F2 : $CHAR5. ;
low = input(scan(F2,1,'-'),best12.);
high= input(scan(F2,-1,'-'),best12.);
if low <= 6 and high >=6;
DATALINES4;
01100170112607 0-12
01100170123968 0-8
01100170124172 0-8
01100170125567 0-8
01100170129403 6-8
01100170130401 8-12
01100170130419 7-12
;;;;
run;
Since you do not have a variable "GSS" in your data, only F1 and F2 you need to discuss the requirements in terms of your variables.
Do yourself a favor and reduce the example data to about 20 rows so you can work out the needed result by hand and show that as a "want" data set.
You have pasted so many unneeded rows that the forum can't run properly .
DATA WORK.test;
LENGTH
F1 $ 14
F2 $ 5 ;
FORMAT
F1 $CHAR14.
F2 $CHAR5. ;
INFORMAT
F1 $CHAR14.
F2 $CHAR5. ;
INPUT
F1 : $CHAR14.
F2 : $CHAR5. ;
low = input(scan(F2,1,'-'),best12.);
high= input(scan(F2,-1,'-'),best12.);
if low <= 6 and high >=6;
DATALINES4;
01100170112607 0-12
01100170123968 0-8
01100170124172 0-8
01100170125567 0-8
01100170129403 6-8
01100170130401 8-12
01100170130419 7-12
;;;;
run;
I should have been clearer: edit your first post. This page takes entirely too long to load.
You should be able to edit the content of your post by clicking on the three dots near the topic. Then delete a lot of lines.
Then show what the intended result should be.
@jcis7 wrote:
Edited and noted for future reference. I thought the 'insert SAS code' window would only show up as a small window on the post with a limited number of lines (like the message you create does). Apologies.
Live an learn, this is the first time I had seen enough data to affect performance and was bit surprised as well. Thank you for fixing the post.
The boxes will take as much as you copy apparently.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.