BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nzelinsky
Calcite | Level 5

 

Hello, 

 

I've been trying to read this dataset into SAS Studio (Release: 3.71 - Basic Edition). As shown below, everything is in double quotes:  

 

"log.radon" "floor" "uranium" "county" "county.name"
"1" "0.78845736036427" "1" "-0.6890475953545" "1" "AITKIN "
"2" "0.78845736036427" "0" "-0.6890475953545" "1" "AITKIN "
"3" "1.06471073699243" "0" "-0.6890475953545" "1" "AITKIN "

(more lines of data here)

"917" "1.6094379124341" "0" "-0.0900242748478867" "84" "WRIGHT "
"918" "1.30833281965018" "0" "0.355286981163884" "85" "YELLOW MEDICINE "
"919" "1.06471073699243" "0" "0.355286981163884" "85" "YELLOW MEDICINE "

 

 

 

data temp;
length ID Radon Floor Uranium County countyname $ 40;
infile "&path/radon.MN.txt" dlm='" "' firstobs=2;
input ID Radon Floor Uranium County countyname$;
run;

All of my numeric variables read in perfectly, but my one character variable will read in only the first word. 

For example, obs 919's county.name is "YELLOW MEDICINE" but I the output just says YELLOW.  

 

 

SAS help.JPG

 

Because SAS stops after it reaches the first space between words and moves the next word to a new variable, I am guessing it's a problem with how I'm setting up dlm.  How can I prevent this miscommunication with SAS so that it reads in everything between double quotes and not just the first word?

 
Note: I've tried dsd but the error message seems to say that won't work with this file.  
"ERROR: Quotes (' or ") have been detected in the delimiter (DLM=)
string. Quotes cannot be used as delimiter characters when the
DSD option is also specified."

 

Also, I apologize for anything in this post that I've formatted poorly or vaguely. I appreciate any formatting feedback, too.  

 

Thank you for any thoughts or suggestions. 

Nicole

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Kurt_Bremser
Super User

Try this:

data temp;
 length ID Radon Floor Uranium County countyname $ 40;
 infile "&path/radon.MN.txt" dlm=' ' dsd firstobs=2; 
 input ID Radon Floor Uranium County countyname$;
run;
Kurt_Bremser
Super User

And here a more specific version, with my ideas for variable types/lengths:

data want;
infile cards dlm=' ' dsd firstobs=2;
length
  ID $3
  Radon 8
  Floor 3
  Uranium 8
  County $2
  countyname $ 40
;
input ID Radon Floor Uranium County countyname;
cards;
"log.radon" "floor" "uranium" "county" "county.name"
"1" "0.78845736036427" "1" "-0.6890475953545" "1" "AITKIN "
"2" "0.78845736036427" "0" "-0.6890475953545" "1" "AITKIN "
"3" "1.06471073699243" "0" "-0.6890475953545" "1" "AITKIN "
"917" "1.6094379124341" "0" "-0.0900242748478867" "84" "WRIGHT "
"918" "1.30833281965018" "0" "0.355286981163884" "85" "YELLOW MEDICINE "
"919" "1.06471073699243" "0" "0.355286981163884" "85" "YELLOW MEDICINE "
;
run;

Note that your initial code would read all variables as $40.

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
  • 2 replies
  • 3606 views
  • 1 like
  • 2 in conversation