BookmarkSubscribeRSS Feed
My_SAS
Calcite | Level 5

Data temp;

infile cards dlm="|";

input bcode$ Rcode $;

cards;

tcs,satyam|123,456

|

rnrl|567

run;

actually if bode is having two obs separated by comma it shoukld go in to two rows and rcode is having two obs separated by , should go to 2 rows

if both are balank it should have single rom  and if it is having only one obs it should be as it is.

output

bcode Rcode

tcs      null

satam  null

    null      123

   null      456

<only one balnk row shuld come as both are blank for both the values>      

rnrl        null

  null        567

2 REPLIES 2
Peter_C
Rhodochrosite | Level 12

Example shows no more than two comma-separated pairs, but that might expand.

Example shows no more than pipe mark(|), but that might expand.

This first code delivers no more than requested;

data want( keep= bcode rcode );

   length bcode rcode $8;

   input;

   if _infile_ = '|' or _infile_ = ' ' then

      do;

         output;

         delete;

      end;

   p1 = scan( _infile_, 1, '|' );

   p2 = scan( _infile_, 2, '|' );

   pcode = ' ';

   bcode = scan( p1,1,',' );

   output;

   bcode = scan( p1,2,',' );

   if bcode ne ' ' then

      do;

         output;

         bcode = ' ';

      end;

   rcode = scan( p2, 1, ',' );

   output;

   rcode = scan( p2, 2, ',' );

   if rcode ne ' ' then

      output;

list;cards;

tcs,satyam|123,456

|

rnrl|567

;

SASJedi
SAS Super FREQ

Try this:

 
Data temp;
   infile datalines dlm="|" truncover dsd;
   input _b:$20. _r:$20.;
   if _infile_='|' then output;
   else do _i=1 to 2;
      bcode=scan(_b,_i,',');
      if not missing(bcode) then output;
      call missing(bcode);
      rcode=scan(_r,_i,',');
      if not missing(rcode) then output;
      call missing(rcode);
   end; 
   drop _:;
datalines;
tcs,satyam|123,456
|
rnrl|567
run;

Check out my Jedi SAS Tricks for SAS Users

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