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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: