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..
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
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.
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.