BookmarkSubscribeRSS Feed
kariarchie
Calcite | Level 5

How do I remove extra character quotation marks that appear in the output of my sas code after I run it?

 

TITLE 'Problem 2 (1)';

DATA Student_por;
INFILE 'E:\SAS HW\Student_por.txt' dlm=';' firstobs=2;
INPUT school $ sex $ age address $ famsize $ Pstatus $ Medu $ Fedu $ Mjob ~$12. Fjob ~$12. reason ~$14. guardian ~$10. traveltime studytime failures schoolsup $
famsup $ paid $ activities $ nursery $ higher $ internet $ romantic $ famrel $ freetime $ goout $ Dalc $ Walc $ health $ absences G1 $ G2 $ G3 $;
RUN;

PROC PRINT DATA=Student_por (firstobs=630);
RUN;

 

All of the character values in this code have a single set of quotation marks except for school, which does not have any quotation marks. But, when I run this, all of the character values in the output receive an extra set of quotations (ex. ""F"" instead of just "F") and school receives one quotation at the beginning (ex. "MS instead of just MS). How do I fix this and keep my output formatted the same as the txt file?

2 REPLIES 2
Patrick
Opal | Level 21

From the docu found here:

Patrick_0-1619310322388.png

I probably would also add infile option truncover or missover and if this is more than an exercise would only use informats with a length specified (not just $).

 

INFILE 'E:\SAS HW\Student_por.txt' dlm=';' firstobs=2 dsd truncover;
Tom
Super User Tom
Super User

Quotes in a delimited file are just there in case the values of the fields contain the delimiter. 

Use the DSD option on the INFILE statement and SAS will automatically remove them.

 

To insert an informat into your INPUT statement and NOT have it read exactly that number of characters use the : modifier, not the ~ modifier.

TITLE 'Problem 2 (1)';

DATA Student_por;
  INFILE 'E:\SAS HW\Student_por.txt' dlm=';' firstobs=2 dsd truncover;
  INPUT school $ sex $ age address $ famsize $ Pstatus $ Medu $ Fedu $
        Mjob :$12. Fjob :$12. reason :$14. guardian :$10. 
        traveltime studytime failures schoolsup $ famsup $ 
        paid $ activities $ nursery $ higher $ internet $ 
        romantic $ famrel $ freetime $ goout $ Dalc $ Walc $ 
        health $ absences G1 $ G2 $ G3 $
  ;
RUN;

PROC PRINT DATA=Student_por (firstobs=630);
RUN;

You appear to be using the informats in your INPUT statement as a way to give SAS a hint that you would like the variable defined longer than the default 8 bytes for character variables.   If you define the variables before hand you don't need to include the informat in this way.  In fact if you define the variables in the order that you want to read them then the INPUT statement can be trivially simple.

DATA Student_por;
  INFILE 'E:\SAS HW\Student_por.txt' dlm=';' firstobs=2 dsd truncover;
  LENGTH school $8 sex $8 age 8 address $8 famsize $8 Pstatus $8 
        Medu $8 Fedu $8 Mjob $12 Fjob $12 reason $14 guardian $10
        traveltime 8 studytime 8 failures 8 schoolsup $8 famsup $8 
        paid $8 activities $8 nursery $8 higher $8 internet $8 
        romantic $8 famrel $8 freetime $8 goout $8 Dalc $8 Walc $8 
        health $8 absences 8 G1 $8 G2 $8 G3 $8
  ;
  INPUT school -- G3 ;
RUN;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 651 views
  • 0 likes
  • 3 in conversation