BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
User_Help
Obsidian | Level 7

Hi,

How to read this in Data Step?

 

 

data a;
	INPUT @ NAME $22. age gender $;
	DATALINES;
RASPUTIN 45 M
BETSY ROSS 62 F
ROBERT LOUIS STEVENSON 75 M
;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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
;

View solution in original post

2 REPLIES 2
Ksharp
Super User
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
;
KachiM
Rhodochrosite | Level 12

@User_Help 

 

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.