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

IP_Admit=0;
if visit_disposition in: ("06","07","08") then IP_Admit=1;

Hello,

I notice in the code above that IP_Admit is missing for all records what could be the reason?

I checked that visit disposition is character

Thankyou

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Reeza wrote:

My mistake, it's an order of operations issue, aside from the others. 

 

You have OUTPUT before you calculate the IP_ADMIT line.

 

MPRINT(RUN_NACRS):   if Cannabis=1 OR poisoning=1 OR Toxic_poisoning=1 then output; <- at this point IP_admit has not be assigned or calculated so it's missing.
MPRINT(RUN_NACRS):   ;
MPRINT(RUN_NACRS):   IP_Admit=0;
MPRINT(RUN_NACRS):   if strip(visit_disposition) in: ("06","07","08") then IP_Admit=1;

It seems to me that @Reeza has provided the answer here.

 

I point out for the benefit of @Baba9 this is why we need to see the ENTIRE code for the DATA step or PROC in question, not selected lines.

--
Paige Miller

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

Since we don't have your data ... all we can do is make suggestions for things that you can look for yourself.

 

Starting with the obvious: Are there actual records where your code should result in IP_Admit=1 ??

 

And obvious #2: are there ERRORs, WARNINGs or NOTEs in the log that would indicate a problem?

--
Paige Miller
Reeza
Super User

Something else that's not shown. 

 

Since you explicitly set it to 0, it should be 0. So it is nested in another IF? Is it reset somewhere else? Does the data step error out?

 

Show the full code and log. 

 


@Baba9 wrote:

IP_Admit=0;
if visit_disposition in: ("06","07","08") then IP_Admit=1;

Hello,

I notice in the code above that IP_Admit is missing for all records what could be the reason?

I checked that visit disposition is character

Thankyou


 

 

AMSAS
SAS Super FREQ

IP_Admit shouldn't be a missing value (. in SAS for numeric)  it can only be 0 or 1

 

See following example log

1078  data _null_ ;
1079      do vd = "05", "06", "07" ;
1080
1081          ipa=0 ;
1082          if vd in:("06","07") then ipa=1 ;
1083          put _all_ ;
1084      end ;
1085  run ;

vd=05 ipa=0 _ERROR_=0 _N_=1
vd=06 ipa=1 _ERROR_=0 _N_=1
vd=07 ipa=1 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

It is difficult to debug based on 2 lines of code, no data and no log

Can you provide a fuller explanation of the issue

Baba9
Obsidian | Level 7
 %run_nacrs(yr=2014);/*15,804*/
MPRINT(RUN_NACRS):   data nacrs2014;
MPRINT(RUN_NACRS):   set dss.nacrs_dss_core_2014_sas;
MPRINT(RUN_NACRS):   if DATE_OF_REGISTRATION < '01JAN2015'd then delete;
MPRINT(RUN_NACRS):   if DATE_OF_REGISTRATION > '31OCT2021'd then delete;
MPRINT(RUN_NACRS):   if DATE_OF_REGISTRATION = . or year(DATE_OF_REGISTRATION) = 9999 then
exclude = 1;
MPRINT(RUN_NACRS):   if exclude ^= 1;
MPRINT(RUN_NACRS):   if submitting_prov_code ne '4' and birthdate_truncated = '9999' then delete;
MPRINT(RUN_NACRS):   if submitting_prov_code = '4' and date_of_registration < '01APR2019'd then
delete;
MPRINT(RUN_NACRS):   if submitting_prov_code = '4' and date_of_registration > '31MAR2021'd then
delete;
MPRINT(RUN_NACRS):   CYEAR=YEAR(DATE_OF_REGISTRATION);
MPRINT(RUN_NACRS):   MONTH = month(DATE_OF_REGISTRATION);
MPRINT(RUN_NACRS):   IF MONTH(DATE_OF_REGISTRATION)=1 or 2 or 3 THEN quarter=1;
MPRINT(RUN_NACRS):   ELSE IF MONTH(DATE_OF_REGISTRATION)=4 or 5 or 6 THEN quarter=2;
MPRINT(RUN_NACRS):   ELSE IF MONTH(DATE_OF_REGISTRATION)=7 or 8 or 9 THEN quarter=3;
MPRINT(RUN_NACRS):   ELSE IF MONTH(DATE_OF_REGISTRATION)=10 or 11 or 12 THEN quarter=4;
MPRINT(RUN_NACRS):   quarter_f =qtr(DATE_OF_REGISTRATION);
MPRINT(RUN_NACRS):   month_txt = put(DATE_OF_REGISTRATION, monName.);
MPRINT(RUN_NACRS):   if gender_code in ("F" , "M") then gender_include=1;
MPRINT(RUN_NACRS):   if gender_include=1;
MPRINT(RUN_NACRS):   format PROVINCE $20.;
MPRINT(RUN_NACRS):   if strip(SUBMITTING_PROV_CODE) in ("4" "5" "8" "9");
MPRINT(RUN_NACRS):   if strip(SUBMITTING_PROV_CODE)= "4" then PROVINCE = "QC";
MPRINT(RUN_NACRS):   else if strip(SUBMITTING_PROV_CODE)= "5" then PROVINCE = "ON";
MPRINT(RUN_NACRS):   else if strip(SUBMITTING_PROV_CODE) in ( "8" ) then PROVINCE = "AB";
MPRINT(RUN_NACRS):   else if strip(SUBMITTING_PROV_CODE) in ( "9" ) then PROVINCE = "BC";
MPRINT(RUN_NACRS):   if AMCARE_GROUP_CODE = "ED" then PT_Type = "Emergency";
MPRINT(RUN_NACRS):   if PT_Type= "Emergency";
MPRINT(RUN_NACRS):   if ED_visit_ind_code = "1" then Unscheduled_emergency = 1;
MPRINT(RUN_NACRS):   if Unscheduled_emergency = 1;
MPRINT(RUN_NACRS):   if AGE_CODE NE "U";
MPRINT(RUN_NACRS):   format age_grp $20.;
MPRINT(RUN_NACRS):   if upcase(age_code) in ('B','D','M') then Age_Grp ="0-9";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E") and age_num <= 9 then Age_Grp="0-9";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E" ) and age_num >=15 and age_num <=24
then Age_Grp="15-24 years";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E" ) and age_num >=25 and age_num <=44
then Age_Grp="25-44 years";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E" ) and age_num >=45 and age_num <=105
then Age_Grp="45-105 years";
MPRINT(RUN_NACRS):   else Age_Grp = "Other";
MPRINT(RUN_NACRS):   if submitting_prov_code ne '4' then do;
MPRINT(RUN_NACRS):   if age_grp = "0-9" and date_of_registration < '01JAN2015'd then delete;
MPRINT(RUN_NACRS):   if age_grp = "0-9" and date_of_registration >= '01OCT2021'd then delete;
MPRINT(RUN_NACRS):   if age_grp in ("15-24 years" "25-44 years" "45-105 years") and
date_of_registration < '01JAN2015'd then delete;
MPRINT(RUN_NACRS):   if age_grp in ("15-24 years" "25-44 years" "45-105 years") and
date_of_registration >= '01NOV2021'd then delete;
MPRINT(RUN_NACRS):   end;
MPRINT(RUN_NACRS):   */ *************************;
MPRINT(RUN_NACRS):   * DEFINE DIAG GROUPS;
MPRINT(RUN_NACRS):   *************************;
MPRINT(RUN_NACRS):   Cannabis=0;
MPRINT(RUN_NACRS):   Poisoning=0;
MPRINT(RUN_NACRS):   Toxic_poisoning=0;
MPRINT(RUN_NACRS):   array code{10} MAIN_PROBLEM OTHER_PROBLEM_1- OTHER_PROBLEM_9;
MPRINT(RUN_NACRS):   do i=1 to 10;
MPRINT(RUN_NACRS):   IF code{i} in : ('T407' 'F12' ) then Cannabis=1;
MPRINT(RUN_NACRS):   IF code[i] in : ('T36','T36','T37','T38','T39',
'T40','T41','T42','T43','T44','T45','T46','T47','T48','T49','T50' ) then Poisoning=1;
MPRINT(RUN_NACRS):   IF code{i} in : ('T51' 'T52' 'T53' 'T54' 'T55' 'T56' 'T57' 'T58' 'T59',
'T60', 'T61', 'T62', 'T63', 'T64', 'T65') then Toxic_poisoning=1;
MPRINT(RUN_NACRS):   end;
MPRINT(RUN_NACRS):   if Cannabis=1 OR poisoning=1 OR Toxic_poisoning=1 then output;
MPRINT(RUN_NACRS):   ;
MPRINT(RUN_NACRS):   IP_Admit=0;
MPRINT(RUN_NACRS):   if strip(visit_disposition) in: ("06","07","08") then IP_Admit=1;
MPRINT(RUN_NACRS):   keep fiscal_year cyear month quarter_f quarter am_care_key amcare_group_code
PT_Type Unscheduled_emergency ED_visit_ind_code visit_disposition IP_Admit Cannabis Poisoning
Toxic_poisoning other_problem_: main_problem date_of_registration submitting_prov_code age_grp
age_code province GENDER_CODE AGE_NUM ;
MPRINT(RUN_NACRS):   run;

NOTE: There were 21031102 observations read from the data set DSS.NACRS_DSS_CORE_2014_SAS.
NOTE: The data set WORK.NACRS2014 has 15804 observations and 50 variables.
NOTE: DATA statement used (Total process time):
      real time           39.09 seconds
      user cpu time       36.42 seconds
      system cpu time     2.64 seconds
      memory              1557.53k
      OS Memory           36352.00k
      Timestamp           2022-03-10 01:58:20 PM
      Step Count                        92  Switch Count  0


Hello,

I noticed that when I moved the flag to the start of the code it worked.

I had not received any errors in any case

Thnx

 

 

Reeza
Super User
MPRINT(RUN_NACRS):   IF MONTH(DATE_OF_REGISTRATION)=1 or 2 or 3 THEN quarter=1;
MPRINT(RUN_NACRS):   ELSE IF MONTH(DATE_OF_REGISTRATION)=4 or 5 or 6 THEN quarter=2;
MPRINT(RUN_NACRS):   ELSE IF MONTH(DATE_OF_REGISTRATION)=7 or 8 or 9 THEN quarter=3;
MPRINT(RUN_NACRS):   ELSE IF MONTH(DATE_OF_REGISTRATION)=10 or 11 or 12 THEN quarter=4;

 

 

MPRINT(RUN_NACRS):   if upcase(age_code) in ('B','D','M') then Age_Grp ="0-9";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E") and age_num <= 9 then Age_Grp="0-9";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E" ) and age_num >=15 and age_num <=24
then Age_Grp="15-24 years";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E" ) and age_num >=25 and age_num <=44
then Age_Grp="25-44 years";
MPRINT(RUN_NACRS):   else if upcase(age_code) in ("Y", "E" ) and age_num >=45 and age_num <=105
then Age_Grp="45-105 years";
MPRINT(RUN_NACRS):   else Age_Grp = "Other";

I don't see any issues with the IP_ADMIT but the sections I've highlighted above are definitely wrong. 

PaigeMiller
Diamond | Level 26

Just a thought. We also need to see the actual macro code that generate the IP_ADMIT lines of code. I'm thinking that perhaps there's something going on that requires %UNQUOTE or other macro "weirdness" involving double quotes.

--
Paige Miller
Reeza
Super User

My mistake, it's an order of operations issue, aside from the others. 

 

You have OUTPUT before you calculate the IP_ADMIT line.

 

MPRINT(RUN_NACRS):   if Cannabis=1 OR poisoning=1 OR Toxic_poisoning=1 then output; <- at this point IP_admit has not be assigned or calculated so it's missing.
MPRINT(RUN_NACRS):   ;
MPRINT(RUN_NACRS):   IP_Admit=0;
MPRINT(RUN_NACRS):   if strip(visit_disposition) in: ("06","07","08") then IP_Admit=1;
PaigeMiller
Diamond | Level 26

@Reeza wrote:

My mistake, it's an order of operations issue, aside from the others. 

 

You have OUTPUT before you calculate the IP_ADMIT line.

 

MPRINT(RUN_NACRS):   if Cannabis=1 OR poisoning=1 OR Toxic_poisoning=1 then output; <- at this point IP_admit has not be assigned or calculated so it's missing.
MPRINT(RUN_NACRS):   ;
MPRINT(RUN_NACRS):   IP_Admit=0;
MPRINT(RUN_NACRS):   if strip(visit_disposition) in: ("06","07","08") then IP_Admit=1;

It seems to me that @Reeza has provided the answer here.

 

I point out for the benefit of @Baba9 this is why we need to see the ENTIRE code for the DATA step or PROC in question, not selected lines.

--
Paige Miller
PaigeMiller
Diamond | Level 26

@Baba9 

 

Please mark the answer from @Reeza as correct, not my answer.

--
Paige Miller
ballardw
Super User

You have

MPRINT(RUN_NACRS):   if DATE_OF_REGISTRATION < '01JAN2015'd then delete;
MPRINT(RUN_NACRS):   if DATE_OF_REGISTRATION > '31OCT2021'd then delete;
MPRINT(RUN_NACRS):   if DATE_OF_REGISTRATION = . or year(DATE_OF_REGISTRATION) = 9999 then
exclude = 1;
MPRINT(RUN_NACRS):   if exclude ^= 1;

 

Think you'll find this works pretty much the same:

 if '01JAN2015'd le DATE_OF_REGISTRATION le  '31OCT2021'd;

Your test here:

if DATE_OF_REGISTRATION = . or year(DATE_OF_REGISTRATION) = 9999 then
exclude = 1;

is redundant. If Date_of_Registration is missing then it is less than any actual date value, such as '01Jan2015'd and had already been deleted. Similar with a year = 9999, that would be greater than 31Oct2021 (or any date prior to 1Jan9999) since you are using the same variable. (Won't even go into the other concerns about dates in the year 9999)

 

There is QTR function that returns the calendar quarter number from a date which you use to create Quarter_f. So, what is supposed to be the difference between Quarter and Quarter_f???

ballardw
Super User

Some possibilities:

Your values do not start with zero but a capital O .

You are looking at a start, the colon in the =:, when the actual occurrence of "06" is in the middle of the string, which will require a different approach.

 

If IP_admit is actually missing and not a value of 0 then you have done something to it after creation or the entire data step did not run due to some error and a prior data set with missing values was not replaced.

 

But this is just guesses because of insufficient information.

PaigeMiller
Diamond | Level 26

So, @Baba9 , based upon all of the above, with the goal of helping you, I request the following information.

 

  1. The entire code for this data step
  2. The entire log for this data step, pasted into the window that appears when you click on the </> icon
  3. Show us a portion of the data as SAS data step code, which you can type in yourself or follow these instructions.

In addition, from now on, every single time, when you are having problems that you need help with, please provide the above three items immediately, in your first post; do not make us ask for them.

--
Paige Miller

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 1319 views
  • 10 likes
  • 5 in conversation