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
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
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
data want1 (drop=i);
set have;
do i=1 to start;
_default_=0;
if i<=end then do;
_default_=1;
end;
output;
end;
run;
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.
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.