Help using Base SAS procedures

How to fill up the range

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

How to fill up the range

Hello,

last few hours I was fighting with something I was thinking will be easy, but I now I need you help.

I have data set that looks like this;

id start end

1 5 12

1 18 56

1 69 89

1 95 110

.

.

2 2 7

2 9 13

2 50 90

.

.

3 4 8

3 10 13

3 93 120

3 125 135

.

.

.

.

Start and end variables are actually beginning and end of a range. Maximum end value is 150 for all ids.

What I would like to have is id and var 1 to 150 with rages filled with 1, and things outside range filled with 0. Beginning and end of range should also be coded as 1.

so for example

id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 var12 var13 var14....var150

1 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0.......

2 0 1 1 1 1 1 1 0 1 1 1 1 1 0 0.....

3 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0...

.

.

.

.

Thank you


Accepted Solutions
Solution
‎01-19-2013 09:14 AM
Super Contributor
Posts: 1,636

Re: How to fill up the range

Hi,

try the code below:

data have;

input id start end;

cards;

1 5 8

1 10 12

2 2 7

2 9 13

;

data temp;

   set have;

   array _var(*) var1-var150;

   do i=1 to 150;

   _var(i)=ifn(i ge start and i le end,1,0);

   end;

proc summary data=temp nway missing ;

  class id;

  var var1-var150; ;

  output out=want (drop=_Smiley Happy max= ;

run;

proc print;run;

View solution in original post


All Replies
Solution
‎01-19-2013 09:14 AM
Super Contributor
Posts: 1,636

Re: How to fill up the range

Hi,

try the code below:

data have;

input id start end;

cards;

1 5 8

1 10 12

2 2 7

2 9 13

;

data temp;

   set have;

   array _var(*) var1-var150;

   do i=1 to 150;

   _var(i)=ifn(i ge start and i le end,1,0);

   end;

proc summary data=temp nway missing ;

  class id;

  var var1-var150; ;

  output out=want (drop=_Smiley Happy max= ;

run;

proc print;run;

Contributor
Posts: 40

Re: How to fill up the range

looks great!

Thanks a lot?

What do think could I go for 150 000 000 variables? Smiley Wink

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 232 views
  • 1 like
  • 2 in conversation