11-18-2016 11:12 AM
I am new to the SAS programming. I having one problem: The SAS could not read two variables from the data set (.dat file). I have enclosed one dimension of the data set below:
Faculty Charles Porter firstname.lastname@example.org 555-8511 AERO
out of 6 variables above(RowID Group FirstName LastName EmailAddress PhoneNumber and Dept);
EmailAddress and PhoneNumber donot show up in the output results. Under the EmailAddress column- output show like this:email:ch and PhoneNumber is blank.
input RowID Group$ FirstName$ LastName$ EmailAddress$ PhoneNumber Department$;
Please let me know where is the probelm in the code to read these two variables correctly.
11-18-2016 11:21 AM
1) There is no "rowid" in the test data you give.
2) Phone number is a text string as "-" is not numeric within a number
3) put a space before the $
4) Set the length of each variable, otherwise it will default to 8 and chop off the end
5) Specify delimiter
data Cusers; length group firstname lastname emailaddress phonenumber department $100; infile datalines dlm=" "; input Group $ FirstName $ LastName $ EmailAddress $ PhoneNumber $ Department $; datalines; Faculty Charles Porter email@example.com 555-8511 AERO ; Run;
This uses datalines, but you can just replace datalines with your file and drop that part.
11-25-2016 09:12 AM
Are you then the same poster as the original question, not sure as the username has changed. If so please mark the correct answer as correct, so its closed. If your not the original poster, your post doesn't make sense?
11-18-2016 11:22 AM
The default length of a character variable when input as your code shows will be 8 characters.
Since your phonenumber varaible was declared to be a numeric variable (no $) it expects nothing but numeric values. The dash in the middle is character and so SAS treats it as non-numeric and you get blank values.
As an example I would suggest looking at using the data import wizard (File>Import Data) and follow the prompts. This will generate and run Proc import code. Take a look at all of the options as they are presented and set a largish value for guessingrows when you find that.
The LOG will show the Data step code generated and you can compare that, or better copy it from the log to the editor and modify as you may want to add labels, change display formats or other operations you want after the input.