Help using Base SAS procedures

how to deal with the blank when input data?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

how to deal with the blank when input data?

Hello, All

Suppose I input just one variable Var:

Data Test;

Informat Var $10.;

input Var;

Cards;

abcdefg

ab cdefg

;

I got the following result:

abcdefg

ab

It seems to me that the informat does not work for records 2 in which only the first two characters were recognized because the third character is a blank.

How to let SAS know that the blank character is also part of the data?


Accepted Solutions
Solution
‎10-02-2011 04:49 AM
Super User
Posts: 10,044

Re: how to deal with the blank when input data?

Posted in reply to littlestone

You can also use a helpful informat $varying.Such as:

data temp;

infile datalines length=len;

input var $varying200. len;

datalines;

............

Ksharp

View solution in original post


All Replies
Super Contributor
Posts: 358

Re: how to deal with the blank when input data?

Posted in reply to littlestone

Hi:

You can use:

input @001 var $char10.;

as long as the data lines start in cc01.

Frequent Contributor
Posts: 89

how to deal with the blank when input data?

Thank you all for helping me.

By the way: what is the difference between input @1 and input @001 ?

Trusted Advisor
Posts: 1,301

how to deal with the blank when input data?

Posted in reply to littlestone

nope

Super User
Super User
Posts: 7,076

Re: how to deal with the blank when input data?

Posted in reply to littlestone

No difference.  They might have used the extra zeros to just make the code look more consistent.

INPUT

  @001 var1 $120.

  @121 var2 5.

...

;

Respected Advisor
Posts: 3,799

Re: how to deal with the blank when input data?

Posted in reply to littlestone

You can also add & after VAR in INPUT statement.  INPUT VAR &;

You should read about LIST, FORMATTED, COLUMN and NAMED input to understand the nuances of the INPUT statement and the interaction of INFORMAT INPUT and INFILE etc.

Solution
‎10-02-2011 04:49 AM
Super User
Posts: 10,044

Re: how to deal with the blank when input data?

Posted in reply to littlestone

You can also use a helpful informat $varying.Such as:

data temp;

infile datalines length=len;

input var $varying200. len;

datalines;

............

Ksharp

Frequent Contributor
Posts: 89

how to deal with the blank when input data?

I apologize for repling late.

Thank you all for great help.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 250 views
  • 6 likes
  • 6 in conversation