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

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;

yuen68
Calcite | Level 5

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...

Tom
Super User Tom
Super User

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;

yuen68
Calcite | Level 5

Thank you so much Tom!

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1191 views
  • 0 likes
  • 2 in conversation