BookmarkSubscribeRSS Feed
RobF
Quartz | Level 8

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:

PROVIDERQ1Q2_2011_denomQ1Q2_2011_numerQ3Q4_2013_denomQ3Q4_2013_numer
CAPITAL_CITY_HOSPITAL10243217
ST_PAULS12982539
UNIVERSITY_MEDICAL_CENTER95716216

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!

4 REPLIES 4
PGStats
Opal | Level 21

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

PG
RobF
Quartz | Level 8

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;

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 4009 views
  • 6 likes
  • 4 in conversation