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

i have attched print screen for your ref..

3 REPLIES 3
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

null       null   

rnrl        null

  null        567

DLing
Obsidian | Level 7

Two fixes:

1) declare the length of the variables up front, don't let SAS guess at it.

2) you need the TRUNCOVER option so SAS doesn't flow over to the next line looking for information

Data temp;

    length bcode rcode $ 12;

    infile cards dlm="|" truncover;

    input bcode $ Rcode $;

cards;

tcs,satyam|123,456

|

rnrl|567

run;

Also posting in the "SAS macro, data step..." section is more appropriate as you are not asking a question about a SAS PROC.

Ksharp
Super User

How about:

Data temp;
infile datalines length=len;
input temp $varying200. len;
datalines;
tcs,satyam|123,456
|
rnrl|567
;
run;
data want(keep=bcode rcode);
 set temp;
 length bcode rcode $ 40;
 a=scan(temp,1,'|');
 b=scan(temp,2,'|');
 if missing(a) and missing(b) then do;
                                     call missing(bcode,rcode);
                                     output;
                                   end;
    else do;
           i=1; bcode=scan(a,i,',');
           do while (not missing(bcode));
            output;
            i+1;
            bcode=scan(a,i,',');
           end;

           j=1;rcode=scan(b,j,',');
           do while (not missing(rcode));
            output;
            j+1;
            rcode=scan(b,j,',');
           end;
         end;
run;

Ksharp

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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