BookmarkSubscribeRSS Feed
saamiq
Calcite | Level 5

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 charles.porter@csu.edu 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.

 

data Cusers;

   infile 'sas/vrdc/......................./comusers.dat';

   input RowID Group$ FirstName$ LastName$ EmailAddress$ PhoneNumber Department$;

Run;


Please let me know where is the probelm in the code to read these two variables correctly.
Thank you,
Sahib

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Several things:

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

Update to:

data Cusers;
  length group firstname lastname emailaddress phonenumber department $100;
   infile datalines dlm=" ";
   input Group $ FirstName $ LastName $ EmailAddress $ PhoneNumber $ Department $;
datalines;
Faculty Charles Porter charles.porter@csu.edu 555-8511 AERO
;
Run;

This uses datalines, but you can just replace datalines with your file and drop that part.

saamiq
Calcite | Level 5
Hello,

Thank you very much it works now. Really appreciated.

Sahib




saamiq
Calcite | Level 5

It works now, Thank you very much.

Sahib

 

saamiqbal
Calcite | Level 5

Hello,

I have accepted a solutions, so problem is solved.

Thank you for your support.

Sahib

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

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?

ballardw
Super User

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.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1092 views
  • 0 likes
  • 4 in conversation