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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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=_:) max= ;

run;

proc print;run;

View solution in original post

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

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=_:) max= ;

run;

proc print;run;

MajaFerencakovic
Fluorite | Level 6

looks great!

Thanks a lot?

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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