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

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

1 ACCEPTED SOLUTION

Accepted Solutions
smantha
Lapis Lazuli | Level 10
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;

View solution in original post

5 REPLIES 5
ballardw
Super User

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 .

smantha
Lapis Lazuli | Level 10
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;
ballardw
Super User

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
Pyrite | Level 9
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.
ballardw
Super User

@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: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 751 views
  • 0 likes
  • 3 in conversation