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;
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
;
data have;
input @1 name $18. @19 city $ state $;
cards;
myself,only here AK
you,and,i, there ID
stuff,1 nowhere UK
;
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.
@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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.