data a;
INPUT;
gender=scan(_infile_,-1,' ');
age=scan(_infile_,-2,' ');
call scan(_infile_,-2,p,l,' ');
name=substr(_infile_,1,p-1);
drop p l;
DATALINES;
RASPUTIN 45 M
BETSY ROSS 62 F
ROBERT LOUIS STEVENSON 75 M
;
data a;
INPUT;
gender=scan(_infile_,-1,' ');
age=scan(_infile_,-2,' ');
call scan(_infile_,-2,p,l,' ');
name=substr(_infile_,1,p-1);
drop p l;
DATALINES;
RASPUTIN 45 M
BETSY ROSS 62 F
ROBERT LOUIS STEVENSON 75 M
;
In addition to the solution given by @Ksharp, it can be solved without using SAS functions. The only requirement is that the value for NAME variable separated by two or more blanks as in:
data a;
INPUT NAME &$22. age gender $;
DATALINES;
RASPUTIN 45 M
BETSY ROSS 62 F
ROBERT LOUIS STEVENSON 75 M
;
run;
I introduced two BLANKS between NAME and AGE and used &$22 to read blank embedded NAME.
SAS Innovate 2025: Save the Date
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!