DATA Step, Macro, Functions and more

SAS could not read variables

Reply
New Contributor
Posts: 3

SAS could not read variables

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

Super User
Super User
Posts: 7,970

Re: SAS could not read variables

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.

New Contributor
Posts: 3

Re: SAS could not read variables

Hello,

Thank you very much it works now. Really appreciated.

Sahib




New Contributor
Posts: 3

Re: SAS could not read variables

It works now, Thank you very much.

Sahib

 

New Contributor
Posts: 2

Accepted a Solution

Hello,

I have accepted a solutions, so problem is solved.

Thank you for your support.

Sahib

 

Super User
Super User
Posts: 7,970

Re: Accepted a Solution

Posted in reply to saamiqbal

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?

Super User
Posts: 11,343

Re: SAS could not read variables

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.

 

Ask a Question
Discussion stats
  • 6 replies
  • 325 views
  • 0 likes
  • 4 in conversation