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.
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?
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
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;
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;
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.
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.
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.