BookmarkSubscribeRSS Feed
Haikuo
Onyx | Level 15

do i=1 to 15;

if dxtrialpci{i} in ('0066', '3604', '3606', '3607') then do;

pcitrial=1;

return; /*leave;*/

end;

end;

'return', 'leave' can do the same thing in THIS context. I suspect 'return' is more efficient, as it does not execute rest of the code.

Ashwini_uci
Obsidian | Level 7

so is this how it will be?

if dxtrialpci{i} in ('0066', '3604', '3606', '3607') then do;

pcitrial=1;

return;

end;

if n  (pr1, pr1, pr3, pr4, pr5, pr6, pr7, pr8, pr9, pr10, pr11, pr12, pr13, pr14, pr15)=0  then pcitrial=. ;

run;

option missing= ' ';

Ashwini_uci
Obsidian | Level 7

sorry about that... somehow after posting, someof the lines got deleted..

so this is how it will be..

option missing= ' ';

            • data library.nismicathcabg4;

set library.nismicathcabg4;

array dxtrialpci{15} pr1-pr15;

pcitrial=0;

do i=1 to 15;

if dxtrialpci{i} in ('0066', '3604', '3606', '3607') then do;

pcitrial=1;

return;

end;

end;

if n  (pr1, pr1, pr3, pr4, pr5, pr6, pr7, pr8, pr9, pr10, pr11, pr12, pr13, pr14, pr15)=0  then pcitrial=. ;

run;

Haikuo
Onyx | Level 15

This one should do.

Ashwini_uci
Obsidian | Level 7

even after modifying.. somehow it is still showing me one missing case as it was shwoing me with earlier version..not sure why?

Haikuo
Onyx | Level 15

If it is just one missing case, it does not hurt to bring it up and check it out?

Ashwini_uci
Obsidian | Level 7

i tried to find out that case using the following.

but the new datset shows no cases at all.. that means there is NOT a single case with missing data for PR1--PR15..

data library.nismicathcabg6;

set library.nismicathcabg4 ;

if pr1= '  ' and pr2= '  ' and pr3= '  ' and pr4= '  ' and pr5= '  ' and pr6= '  ' and pr7= '  ' and pr8= '  ' and pr9= '  ' and pr10= '  ' and pr11= '  ' and pr12= '  ' and pr13= '  '

and pr14= '  ' and pr15= '  ';

run;

Haikuo
Onyx | Level 15

I am a bit confused now. So after you dig that record out, what exactly it looks like? I suppose they are all numeric, then why you use pr1=' ' etc to retrieve it? why not use pr1=. and ...

if you want to save some typing, use nmiss() ,cmiss() or coalesce() .

or if you don't want to be concern of their type, use if missing(pr1) and missing (pr2)...

Ashwini_uci
Obsidian | Level 7

There is not such record with data missing for all from PR1-PR15.

These are variables with  non-numeric data and the missing is indicated as " " that is why Ihad use the above code..

I wrote all that just to make sure if there is or there isnt such case..

what you suggested in the last line, "use if missing(pr1) and missing (pr2)..." that also I will have to ffor all 15 variables..so its tooo a bit of writing.

Ashwini_uci
Obsidian | Level 7

I used that program for some other codes from PR1-PR15, but it still shows me one missing case, and the one you posted in your first response, is not showing me any missing case,

I guess there is something in this  program..that i copied below..that is showing one missing case.

option missing= ' ';

            • data library.nismicathcabg4;

set library.nismicathcabg4;

array dxtrialpci{15} pr1-pr15;

pcitrial=0;

do i=1 to 15;

if dxtrialpci{i} in ('0066', '3604', '3606', '3607') then do;

pcitrial=1;

return;

end;

end;

if n  (pr1, pr1, pr3, pr4, pr5, pr6, pr7, pr8, pr9, pr10, pr11, pr12, pr13, pr14, pr15)=0  then pcitrial=. ;

run;

Ashwini_uci
Obsidian | Level 7

also Haikuo,

I am running some other variables using your version of array.. and that shows me a missing case as a blank cell. Where and what do I say in the program to indicate the missing data as " ." (a period ?)

Ashwini_uci
Obsidian | Level 7

Thanks a lot Haikuo! It was a tremendous help for you today. I used your version of array program and also verified the results.

Thanks again,

Best

Ashwini

Ashwini_uci
Obsidian | Level 7

* from you.. (sorry typo )_ Smiley Happy

Haikuo
Onyx | Level 15

where is your do-loop? you may want to post your full code, or like you said, use the one in my first reply to you.

ballardw
Super User

Instead of trying to incorporate in the array test the values first;

if cats( of Pr:) = '' then pci=.; /* assums only the variablse PR1- PR15 named starting with PR, may need ( of PR1-PR15)*/

else do i=1 to15;

...

end;

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 29 replies
  • 2609 views
  • 0 likes
  • 4 in conversation