BookmarkSubscribeRSS Feed
m_sd
Calcite | Level 5

Hello,

 

I'm trying to restrict a birth dataset for a class (see below). I'm new to coding so I'm sure my code isn't the most eloquent, however, regardless of what code I try to run SAS Studio is taking a long time to process. Any suggestions? Thanks!

 

DATA G7Data.Restricted;
SET RMG7.CO_BIRTH_FALL2018_PRMD6626 (KEEP = ID MatTrans Income MEduc BWGr Apgar5 Apgar10
Plurality FacilityTpye AttendantType Gindex BirthState
EstGest EstGestOb EstGestClin);
IF Plurality = "1" THEN OUTPUT G7Data.Restricted;
IF AttendantType = "1" OR
AttendantType = "2" OR
AttendantType = "3" OR
AttendantType = "4" THEN OUTPUT G7Data.Restricted;
IF FacilityType = "1" THEN OUTPUT G7Data.Restricted;
IF BirthState = "99999000006" THEN OUTPUT G7Data.Restricted;
IF M_Age GE 18 AND LE 35 THEN OUTPUT G7Data.Restricted;
RUN;
3 REPLIES 3
Shmuel
Garnet | Level 18

If there is more then one true condition shall the code output be duplicated ?

 

If the answer is negative change the inner step code to: 

IF Plurality = "1"                OR
   ("1" le AttendantType le "4")  OR
    FacilityType = "1"            OR
    BirthState = "99999000006"    OR
   (M_Age GE 18 AND M_Age LE 35)
    THEN OUTPUT G7Data.Restricted;

I see no reason that code will run for long time unless the dataset is very big.

m_sd
Calcite | Level 5

I had to restart SAS Studio for the code to work, but I realized the code I wrote was duplicating. Thank you for that suggestion, I'm going to try it out!

ballardw
Super User

If you want to apply multiple restrictions use AND between the different qualifiers.

 

DATA G7Data.Restricted;
	SET RMG7.CO_BIRTH_FALL2018_PRMD6626 (KEEP = ID MatTrans Income MEduc BWGr Apgar5 Apgar10
						Plurality FacilityTpye AttendantType Gindex BirthState
					        EstGest EstGestOb EstGestClin);
   where Plurality = "1" 
	 and  AttendantType in( "1" "2""3"  "4") 
    and  FacilityType = "1" 
	 and BirthState = "99999000006" 
	 and 18 le M_Age LE 35 
  ;
RUN;

The IN operator is basically a shorthand for Variable = "value" or variable = "other value" or variable= "yet another value"

with some added advantages for ranges of integer values.

SAS supports   a < b < c type comparisons so you can more easily see things than having to use an AND with two comparisons.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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