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
;
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.
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.