BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Background: I have about 400 blood tests that I am looking at. I want to know whether for tests of type 2 in the range 10-14 there was a subsequent test within 90 days. If not, I then want to know whether there was a test within 120 days. I created a new variable for each of these. The array you see is because these 400 tests are in 87 patients and 39 is the max number of results any patient has. However, I wanted to make sure that the recoding was working (I need to do this again for a variety of other ranges and timeframes and the recoding would make it simpler -- for my brain, anyway) so I tried to test it by changing the second bit -- but when I did that, the output for the first part changed. Why is it doing that?

The preview makes it seem that the code and output I want to share will not be displayed, so I will post those as a reply to myself
9 REPLIES 9
deleted_user
Not applicable
My code is too long. So, here are a few pieces:
2nd part of code
if b1014in90 = 'No' and (timetonext(i)>120 or timetonext(i)=.)
then do;
b1014in120 = 'No';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;

alternate code:
if blltype(i) = 2 and 9 < blltest(i) < 15 and (timetonext(i)>120 or timetonext(i)=.)
then do;
b1014in120 = 'No';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
deleted_user
Not applicable
Output:
2nd part of code
b1014in90 Freq Percent Cum Freq Cum Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
No 27 72.97 27 72.97
Yes 10 27.03 37 100.00

b1014in120 Freq Percent Cum Freq Cum Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
No 17 94.44 17 94.44
Yes 1 5.56 18 100.00

alternate code
b1014in90 Freq Percent Cum Freq Cum Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
No 20 60.61 20 60.61
Yes 13 39.39 33 100.00

b1014in120 Freq Percent Cum Freq Cum Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
No 20 100.00 20 100.00
Cynthia_sas
SAS Super FREQ
Hi sometimes the < and > in your code causes the forum posting to "act funny". There are 2 things you can do to help insure that your code looks correct when posted:
-- you can put your code within [pre] and [/pre] tags when you copy the code to the forum post message box.
-- you can do a global search/replace on a copy of the code (before you paste it into the post message box) -- search for < and change it to &lt; and then do the same search and replace, to change > to &gt;

This forum posting talks about other ways to post your code:
http://support.sas.com/forums/thread.jspa?threadID=7550

cynthia
deleted_user
Not applicable
Thanks, Cynthia.

ORIGINAL CODE
[pre]
data BloodEnv3;
set BloodEnv2;
array blltype(39) blltype1-blltype39;
array blltest(39) blltest1-blltest39;
array timetonext(39) timetonext1-timetonext39;
format b1014in90 b1014in120 $3.;

/* cap BLL 10-14 within 90 days as recommended or not*/
do i = 1 to 39;
if blltype(i) = 2 and 9 < blltest(i) < 15 and (timetonext(i) >90 or timetonext(i)=.)
then do;
b1014in90 = 'No';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
if blltype(i) = 2 and 9 < blltest(i)< 15 and timetonext(i) <=90
then do;
b1014in90 = 'Yes';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
end;

/* cap BLL 10-14 within 120 days if 90 day timeframe not met*/
do i = 1 to 39;
if b1014in90 = 'No' and (timetonext(i)>120 or timetonext(i)=.)
then do;
b1014in120 = 'No';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
if b1014in90 = 'No' and 91 < timetonext(i)<=120
then do;
b1014in120 = 'Yes';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
end;
run;
[/pre]

ORIGINAL OUTPUT
b1014in90 Frequency Percent Frequency Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
No 27 72.97 27 72.97
Yes 10 27.03 37 100.00

ALTERED CODE
[pre]
data BloodEnv3;
set BloodEnv2;
array blltype(39) blltype1-blltype39;
array blltest(39) blltest1-blltest39;
array timetonext(39) timetonext1-timetonext39;
format b1014in90 b1014in120 $3.;

/* cap BLL 10-14 within 90 days as recommended or not*/
do i = 1 to 39;
if blltype(i) = 2 and 9 < blltest(i) < 15 and (timetonext(i) >90 or timetonext(i)=.)
then do;
b1014in90 = 'No';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
if blltype(i) = 2 and 9 < blltest(i)< 15 and timetonext(i) <=90
then do;
b1014in90 = 'Yes';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
end;

/* cap BLL 10-14 within 120 days if 90 day timeframe not met*/
do i = 1 to 39;
if blltype(i) = 2 and 9 < blltest(i) < 15 and (timetonext(i)>120 or timetonext(i)=.)
then do;
b1014in120 = 'No';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
if blltype(i) = 2 and 9 < blltest(i) < 15 and 91 < timetonext(i)<=120
then do;
b1014in120 = 'Yes';
put blltype(i)= blltest(i) = timetonext(i) = ;
if blltype(i) = 2 then output;
end;
end;
run;
[/pre]

ALTERED OUTPUT
b1014in90 Frequency Percent Frequency Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
No 20 60.61 20 60.61
Yes 13 39.39 33 100.00

Frequency Missing = 129


Cumulative Cumulative
b1014in120 Frequency Percent Frequency Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
No 20 100.00 20 100.00

Frequency Missing = 142
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Highly suggest you use one or more of the following SAS statements to help diagnose your program:

PUTLOG '>DIAG-nn' / _ALL_;

where "nn" is a unique number/value for each PUTLOG statement for easy identification when you are debugging your program execution.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Scott, I did that, but I don't understand how it helps. What am I looking for in the log now?
Cynthia_sas
SAS Super FREQ
Hi:
Somehow you are bypassing the logic that sets 'No' or 'Yes'...so the first thing I'd try, maybe at the end of the DATA step is something like:
[pre]
if b1014in120 not in ('No', 'Yes') then put _all_;
[/pre]

You need to find out what the observations have in common (the ones where b1014in120 was not set properly) to detect how the logic needs to change.

cynthia
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You either need to add more variables to your TABLES (PROC FREQ) statement, or you need to have some IF THEN PUTLOG....; logic to dump a condition where you are seeing blank/missing value result.

Also, you have an OUTPUT; statement in multiple DO / END loops, but notice that you cannot set variable values for both of the ANALYSIS variables used in the FREQ. So, as you loop through the first DO / END 39 times, the variable in the second DO / END loop will have a blank/missing value, correct?

Start out by adding more variables to your PROC FREQ TABLES statement, such as:

PROC FREQ;
TABLES VARA*VARB*VARC / LIST MISSING;
RUN;

You should be abe to see better under what conditions you are getting the blanks.

Also, you may want to just STOP; at the end of the DATA step and then do a simple PROC PRINT -- work with test-data scenarios - SMALL ONES first before trying to conquer all conditions in your data. Most of all you really need to know your data and the SAS programming logic you intend to use, whether you developed the code or inherited it from someone else.

Scott Barry
SBBWorks, Inc.
Flip
Fluorite | Level 6
You have code in the first set limiting the loops through the second loop.
if b1014in90 = 'No'

So your looping and multiple output statements are creating records for which b1014in90 has not been assigned. These are the missing values from what I can see. Also not having that condition is probably increasing your record count and thus changing your frequencies.

I think having 2 sets of DO looping and multiple outputs is messing you up. I would suggest reviewing your program flow.

Also what you should be looking for in the log is what is causing the missing values.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 750 views
  • 0 likes
  • 4 in conversation