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-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
  • 4 replies
  • 899 views
  • 0 likes
  • 2 in conversation