Good day:
I have this data set:
data have;
input Order ID;
cards;
1 ROBERT
2 CARLOS
3 EDWARD
4 JHON
;
now i need this:
ORDER ID STATUS
1 ROBERT ok
1.1 ROBERT ok
1.2 ROBERT ok
1.3 ROBERT ok
2 CARLOS ok
2.1 CARLOS ok
2.2 CARLOS ok
2.3 CARLOS ok
3 EDWARD ok
3.1 EDWARD ok
3.2 EDWARD ok
3.3 EDWARD ok
4 JHON ok
4.1 JHON ok
4.2 JHON ok
4.3 JHON ok
Hi @jonatan_velarde,
Another alternative:
data have;
input Order ID $8.;
cards;
1 ROBERT
2 CARLOS
3 EDWARD
4 JHON
;
data want;
set have;
retain status 'OK';
do order = order to (order + 0.3) by 0.1;
output;
end;
run;
Kind regards,
Amir.
data have; input Order ID $; cards; 1 ROBERT 2 CARLOS 3 EDWARD 4 JHON ; data want; set have; status='ok'; output; do i=1 to 3; order=order+0.1;output; end; drop i; run;
data have;
input Order ID $;
cards;
1 ROBERT
2 CARLOS
3 EDWARD
4 JHON
;
data want(drop = i o);
set have(rename = Order = o);
status = 'ok';
order = put(o, 8. -l);
output;
do i = 1 to 3;
order = catx('.', cats(o), i);
output;
end;
run;
Hi @jonatan_velarde,
How about:
data have;
input Order ID $8.;
cards;
1 ROBERT
2 CARLOS
3 EDWARD
4 JHON
;
data want(drop = i);
set have;
retain status 'OK';
do i = 1 to 4;
output;
order = order + 0.1;
end;
run;
Kind regards,
Amir.
Hi @jonatan_velarde,
Another alternative:
data have;
input Order ID $8.;
cards;
1 ROBERT
2 CARLOS
3 EDWARD
4 JHON
;
data want;
set have;
retain status 'OK';
do order = order to (order + 0.3) by 0.1;
output;
end;
run;
Kind regards,
Amir.
Hello @jonatan_velarde,
I would consider storing the two levels of ORDER (integer and decimal part in your description) in separate variables if possible.
data test;
retain order1 order2 id;
retain status 'ok';
set have(rename=(order=order1));
do order2=., 1 to 3;
output;
end;
run;
Thus you would avoid these potential issues:
607 data _null_; 608 if 2.2+0.1 ne 2.3 then put 'Surprised?'; 609 run; Surprised? NOTE: DATA statement used (Total process time):So you would need to modify the other code suggestions (e.g., apply the ROUND function) to avoid unexpected results. Plus the issue if n>9.
Another approach, using Cartesian product, that also gives you the flexibility of using letters, example, in the order variable.
data have;
input Order ID $;
cards;
1 ROBERT
2 CARLOS
3 EDWARD
4 JHON
;
data seq;
input n;
cards;
0.0
0.1
0.2
0.3
;
proc sql;
create table Cart as
select have.*,seq.*
from have, seq;
quit;
data want;
set Cart;
retain status 'ok';
Order=order+n;
drop n;
run;
proc sort;
by Order ID;
run;
proc print;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: