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: 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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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