data test;
infile datalines missover;
input x y$ z;
datalines;
34 aman 56
56 vikash 34
34 aman 56
56 vikash 34
34 aman
56 34
aman 56
56 vikash 34
34 aman 56
56 vikash
34 56
56 vikas
;
run;
proc print; run;
please let me know how i can read records in correct format...
Then try:
data test;
infile datalines truncover;
input x 1-2;
_infile_=substr(_infile_,3);
y=scan(_infile_,1);
if not anyalpha(y) then do;
call missing(y);
z=input(scan(_infile_,1),8.);
end;
else z=input(scan(_infile_,2),8.);
datalines;
34 aman 56
56 vikash 34
34 aman 56
56 vikash 34
34 aman
56 34
aman 56
56 vikash 34
34 aman 56
56 vikash
34 56
56 vikas
;
At least for your example, the following would work:
data test;
infile datalines truncover;
input @;
_infile_=tranwrd(_infile_,' ',' ');
_infile_=tranwrd(_infile_,' ',' . ');
input x 1-2 y $ z;
datalines;
34 aman 56
56 vikash 34
34 aman 56
56 vikash 34
34 aman
56 34
aman 56
56 vikash 34
34 aman 56
56 vikash
34 56
56 vikas
;
Thank you very much for your kind help.
sir i would like to add one thing that your ans is suitable for only this sample data in exact this format. but if i will change place of any field value(means adding one or more space in between) so it will give wrong ans. which is possible to come in complete population.
i tried something but it is not working in name field.
data test;
infile datalines truncover dlm=",";
input @;
_infile_=tranwrd(_infile_,' ',",");
input x 1-2 y $ z;
datalines;
34 aman 56
56 vikash 34
34 aman 56
56 vikash 34
34 aman
56 34
aman 56
56 vikash 34
34 aman 56
56 vikash
34 56
56 vikas
;
run;
Kindly suggest me ....
Then try:
data test;
infile datalines truncover;
input x 1-2;
_infile_=substr(_infile_,3);
y=scan(_infile_,1);
if not anyalpha(y) then do;
call missing(y);
z=input(scan(_infile_,1),8.);
end;
else z=input(scan(_infile_,2),8.);
datalines;
34 aman 56
56 vikash 34
34 aman 56
56 vikash 34
34 aman
56 34
aman 56
56 vikash 34
34 aman 56
56 vikash
34 56
56 vikas
;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.