BookmarkSubscribeRSS Feed
MarcusX
Calcite | Level 5

I am encountering an issue with my input statement that is dealing with space in the raw file. I have a raw file that has the first and last name but there exists a space in between them. I want to read them as a fullname but the space delimiter in between is causing the character to spill into the next variable which is city. How would one go about reading the fullname in such a situation? I currently have the following statement :

DATA HW2.PRES1;
INFILE PRES1;
INPUT FULLNAME $18. CITY $15. STATE $15. ASP 2. BOD DATE9. TERM  VOTES   PERCVOTE;
CARDS;
RUN;

6 REPLIES 6
novinosrin
Tourmaline | Level 20
Do you have two or more blank spaces between last name and city? can you confirm this? Also post a sample plz
MarcusX
Calcite | Level 5
yes i do.
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

if your records are fixed position this will work

 

data have;
	input @1 name $18. @19 city $;
cards;
myself,only       here
you,and,i,        there
stuff,1           nowhere
;
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
data have;
	input @1 name $18. @19 city $ state $;
cards;
myself,only       here              AK
you,and,i,        there ID
stuff,1           nowhere  UK
;
Astounding
PROC Star

You will have to show the actual program you ran that contains the problem.  This program does not have the problem you describe.  It reads everything in columns 1 through 18 as the value of FULLNAME, blanks included.

ballardw
Super User

@MarcusX wrote:

I am encountering an issue with my input statement that is dealing with space in the raw file. I have a raw file that has the first and last name but there exists a space in between them. I want to read them as a fullname but the space delimiter in between is causing the character to spill into the next variable which is city. How would one go about reading the fullname in such a situation? I currently have the following statement :

DATA HW2.PRES1;
INFILE PRES1;
INPUT FULLNAME $18. CITY $15. STATE $15. ASP 2. BOD DATE9. TERM  VOTES   PERCVOTE;
CARDS;
RUN;


I would read the name as components, firstname and lastname, then concatenate if I really need the full name as a single variable.

Fullname = catx(' ', firstname, lastname);

If you search this forum carefully you will find the reverse question of "I have a full name and need the first and last (and middle) as separate" moderately often.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1088 views
  • 2 likes
  • 5 in conversation