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

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

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
  • 706 views
  • 1 like
  • 2 in conversation