I have to run Chi-squared tests on a series of small datasets contained in Excel spreadsheets.
Is there an easy way to simply cut and paste the cells containing the data from Excel directly into a data input statement in the SAS editor?
I'm running into formatting issues with tabs and character length formats. I've tried copying & pasting the data from Excel to Notepad first, then copying from Notepad to the SAS editor, but no luck.
Here's an example of inpatient count data listed by hospital in an Excel spreadsheet:
PROVIDER | Q1Q2_2011_denom | Q1Q2_2011_numer | Q3Q4_2013_denom | Q3Q4_2013_numer |
CAPITAL_CITY_HOSPITAL | 102 | 4 | 321 | 7 |
ST_PAULS | 129 | 8 | 253 | 9 |
UNIVERSITY_MEDICAL_CENTER | 95 | 7 | 162 | 16 |
which I want to cut & paste into SAS as follows:
data hospital_data;
input PROVIDER $50. Q1Q2_2011_denom Q1Q2_2011_numer Q3Q4_2013_denom Q3Q4_2013_numer;
cards;
CAPITAL_CITY_HOSPITAL 102 4 321 7
ST_PAULS 129 8 253 9
UNIVERSITY_MEDICAL_CENTER 95 7 162 16
;
run;
However the output data in hospital_data lumps the provider name and the inpatient count data together under PROVIDER and leaves a blank in the Q1Q2_2011_denom column.
Any thoughts how to expedite quick & dirty cut and pastes from Excel to SAS?
Thanks!
Add a colon before the informat $50.
input PROVIDER :$50. Q1Q2_2011_denom Q1Q2_2011_numer Q3Q4_2013_denom Q3Q4_2013_numer;
That way you will be reading PROVIDER with formatted list input, i.e. the input field will end at the first space encountered.
PG
You might find some useful code at: Copy and Paste from Excel to SAS - sasCommunity
Thank you for the suggestions.
In fact, I've also found that cutting and pasting data from Excel into this editor window for a new SAS Discussion question automatically formats the data. I can then cut paste from the editor window directly into a data step & SAS creates a correctly formatted dataset.
data hospital_data;
length provider $50.;
input PROVIDER $ Q1Q2_2011_denom Q1Q2_2011_numer Q3Q4_2013_denom Q3Q4_2013_numer;
cards;
…
run;
Personally I just copy and paste and then issue a change command to change the tabs to |.
Then in the DATA step add an INFILE statement to let SAS know to use DSD option.
input cards dsd dlm='|' truncover;
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.