Hi all, i'm writing a script for data step.
the raw file is like this:
(dlm=,)
ID,visit_freq,sales1,sales2,sales3,sales4
A,3,2,3,
B,4,1,,2,4
C,2,1,2
output should be like this:
ID sales
A 2
A 3
A .
B 1
B .
B 2
B 4
C 1
C 2
i have used do while but the output is a bit different:
data sales1;
infile ' data path' dlm=',' missover;
input ID$ visit_freq @;
do until (visit_freq=0);
visit_freq=visit_freq-1;
input sales @;
output;
end;
drop visit;
run;
finally i got the output is different the expected (problem of observation B)... may anyone help on this????
Thanks in advance!!
You need the dsd option so that treats the adjacent delimiters (,,) as meaning a missing value. Otherwise it treats them the same way it would treat multiple spaces in normal list mode input.
data sales1;
infile 'data path' DSD dlm=',' TRUNCOVER;
input ID $ visit_freq @;
do until (visit_freq=0);
visit_freq=visit_freq-1;
input sales @;
output;
end;
drop visit_freq;
run;
Looks like your data tells you how many values to read. Use an iterative loop instead.
do i=1 to visit_freq ;
input sales @;
output ;
end;
Thanks Tom,
Actually it's similar to the do while/ until concept and the result would be like this?
ID sales
A 2
A 3
A .
B 1
B 2 **
B . **
B 4
C 1
C 2
i cant figure out why the rows with ** are swapped...
You need the dsd option so that treats the adjacent delimiters (,,) as meaning a missing value. Otherwise it treats them the same way it would treat multiple spaces in normal list mode input.
data sales1;
infile 'data path' DSD dlm=',' TRUNCOVER;
input ID $ visit_freq @;
do until (visit_freq=0);
visit_freq=visit_freq-1;
input sales @;
output;
end;
drop visit_freq;
run;
Thank you so much Tom!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.