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