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

Hi all,

I have the data set provided below:-

Data have;

input start end score;

Datalines;

1 0 0.22

1 1 0.58

2 2 0.89

6 3 0.36

3 2 0.77

1 0 0.89

1 1 0.89

;

run;

“start” variable shows number of observations at start of period, while “end” shows the number of default observations at the end of period. With given data/scenario I have to create default indicator with 1 as default and 0 as not default. For example observation number 4 has value 6 for start variable and it has 3 defaults within the end variable so I need to replicate that observation 6 times i.e. 3 times with value 1 in the default indicator(“def_indi”) and 3 times with value 0.

Through my code I find myself successful in replicating the observation but not in creating the default indicator as desired. The desired data “want” is provided below.

My partial code:-

data want;

set have;

do i= 1 to (start);

def_indi=1;

output;

end;

run;

Data want;

input start end score Def_indi;

Datalines;

1 0 0.22 0

1 1 0.58 1

2 2 0.89 1

2 2 0.89 1

6 3 0.36 0

6 3 0.36 0

6 3 0.36 0

6 3 0.36 1

6 3 0.36 1

6 3 0.36 1

3 2 0.77 0

3 2 0.77 1

3 2 0.77 1

1 0 0.89 0

1 1 0.89 1

;

run;

I need it urgently so I would be highly thankful if someone could help me with it.

Tony

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK.

Data have;
input start end score;
Datalines;
1 0 0.22
1 1 0.58
2 2 0.89
6 3 0.36
3 2 0.77
1 0 0.89
1 1 0.89
;
run;
data want;
 set have;
 do i=1 to start-end;
  Def_indi=0;
  output;
 end;
 do i=1 to end;
  Def_indi=1;
  output;
 end;
 drop i;
run;

Ksharp

View solution in original post

2 REPLIES 2
Ksharp
Super User

OK.

Data have;
input start end score;
Datalines;
1 0 0.22
1 1 0.58
2 2 0.89
6 3 0.36
3 2 0.77
1 0 0.89
1 1 0.89
;
run;
data want;
 set have;
 do i=1 to start-end;
  Def_indi=0;
  output;
 end;
 do i=1 to end;
  Def_indi=1;
  output;
 end;
 drop i;
run;

Ksharp

Varun_Chhabra
Calcite | Level 5

data want1 (drop=i);

set have;

do i=1 to start;

_default_=0;

if i<=end then do;

  _default_=1;

end;

output;

end;

run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1846 views
  • 5 likes
  • 3 in conversation