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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 623 views
  • 4 likes
  • 3 in conversation