DATA Step, Macro, Functions and more

INFORMAT: How not to read (') ?

Accepted Solution Solved
Reply
Contributor
Posts: 72
Accepted Solution

INFORMAT: How not to read (') ?

[ Edited ]

Hi SAS users,

 

I have a data set (csv file) including several variables. The values of the variables include a (') at the begining like below . Could you please advise how to use INFORMAT, and not to read the (') and just the numbers/characters ?

 

'WV99

 

Thank you


Accepted Solutions
Solution
‎02-11-2016 12:41 PM
Super Contributor
Posts: 490

Re: INFORMAT: How not to read (') ?

[ Edited ]
Posted in reply to almmotamedi

You can us COMPRESS function to get rid of all single quotation in your variables. Or you can use SUBSTR if your variable contains other desired single quotation other than the one in the beginning.

For example

data test;
input x $;
x=compress(x,"'");
cards;
're34
'466
'terew
;
run;

 

View solution in original post


All Replies
Respected Advisor
Posts: 4,930

Re: INFORMAT: How not to read (') ?

Posted in reply to almmotamedi

Share with us the code you tried and a few lines of the csv file.

PG
Contributor
Posts: 72

Re: INFORMAT: How not to read (') ?

Here is the code:

 

data ABC.Entire_database_second;

infile "/v_share/Xiaomin/SCOPES/sas_dataset/Oct-08-2015/ScopesCalculations_SecondaryConstruction_*" linesize = 300 firstobs = 2 DSD ;

 

 

Informat
C_ST $3.0
C_DSTRB_AREA $5.0
N_RSK $7.0

 

input
C_ST $
C_DSTRB_AREA $
N_RSK $

 

run;

 

and attached is the csv file. Thank you

Solution
‎02-11-2016 12:41 PM
Super Contributor
Posts: 490

Re: INFORMAT: How not to read (') ?

[ Edited ]
Posted in reply to almmotamedi

You can us COMPRESS function to get rid of all single quotation in your variables. Or you can use SUBSTR if your variable contains other desired single quotation other than the one in the beginning.

For example

data test;
input x $;
x=compress(x,"'");
cards;
're34
'466
'terew
;
run;

 

Contributor
Posts: 72

Re: INFORMAT: How not to read (') ?

Posted in reply to mohamed_zaki
Thank you
Respected Advisor
Posts: 3,799

Re: INFORMAT: How not to read (') ?

Posted in reply to almmotamedi

The $QUOTE informat will also do that.  An you can associate the INFORMAT with all character variables.

33         data test;
34            input x:$quote.;
35            put x=;
36            list;
37            cards;

x=re34
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                     
38         're34
x=466
39         '466
x=terew
40         'terew

 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 293 views
  • 4 likes
  • 4 in conversation