BookmarkSubscribeRSS Feed

Hi all,

I am trying to create indicator variables, based on information in other variables in my table.  I have a data set in wide format (which I created from long) that has subject data at many (up to 700) different timepoints.  Basically, if ANY of those time points have a specific value, I'd like to create an indicator.  For example, if any of T1-T100 = 1, then I want INDICATOR=1.

Can I have SAS specify a range of variable to check in my IF statement?  I know I can us multiple "or" statements, but this is not practical, given the large number of time points.

Also, I considered writing it into my array when I converted from long to wide format, but this did not seem to work and I did not see documentation on this particular issue.

This is what I tried..

data wide (keep=id T1-T&mm var1-var&mm);

array T(&mm);

array var(&mm);

do j = 1 by 1 until (last.id);

set data1;

by id;

T(j) = Time;

var(j) = score;

if var(j) = 20 then HIGH = 1; else HIGH=0;

end;

Thanks for your help!

-Katie

2 REPLIES 2
data_null__
Jade | Level 19

I think WHICHN will be helpful.

has1 = whichN(1,of T1-T100);

if has1 is greater than 1 then the range contains a least 1 variable with the target.

Thanks, data_null, this is helpful.  It will return the ordered number of the first variable it hits, correct?  So if my data row were to look like

T1 T2 T3 T4

8   9  10  7

has1 = whichN(9, of T1-T4)

would return has1=2

This could work, because then I would just need to add a line of code if has1 > 0 then has1=1. 

Thanks!

-Katie

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
  • 2 replies
  • 2908 views
  • 3 likes
  • 2 in conversation