Importing only part of an Excel File into SAS

Reply
Contributor
Posts: 57

Importing only part of an Excel File into SAS

Hello,

Is it possible when importing a file into SAS to specify a certain set of rows you want to import?  For example if my excel file has a column called say "CODE" and there are 2000 differnt codes in that file so 2000 rows - each row contains a unique code, is it possible to specify in the SAS import statement to say only import codes that are in the range of 440-44. Or be able to  specify two ranges so only import codes 1-10 and then codes 300-350  and leave everything else without having to individual list out each one I want to import.  Below is an example of the excel file and the current SAS statement I use to import the WHOLE file.

Many thanks in advance

Lisa

CodeTypeCode
ICD9_DX'410'
ICD9_DX'411'
ICD9_DX'398'
ICD9_DX'402'
ICD9_DX'428'
ICD9_DX'440'
ICD9_DX'441'
ICD9_DX'442'
ICD9_DX'443'
ICD9_DX'444'
ICD9_DX'445'
ICD9_DX'446'
ICD9_DX'447'
ICD9_DX'430'
ICD9_DX'431'
ICD9_DX'432'
ICD9_DX'433'
ICD9_DX'435'
ICD9_DX'290'
ICD9_DX'291'
ICD9_DX'294'
ICD9_DX'491'
ICD9_DX'492'
ICD9_DX'493'
ICD9_DX'710'
ICD9_DX'714'
ICD9_DX'725'

libname Codes excel

  "C:\Codelist..xlsx"  

  header = yes

  mixed = yes;

run;

I want to be able to add in a line of code  to specify certain ranges:

libname Codes excel

  "C:\Codelist..xlsx"  

  header = yes

  mixed = yes;

********INSERT NEW CODE -  ONLY IMPORT CODES THAT ARE IN THE RANGE OF 440-447 ******

run;

Super User
Posts: 11,343

Re: Importing only part of an Excel File into SAS

Posted in reply to lisahoward

If you are talking about a range of values for a variable add a dataset option where clause on the output dataset. You don't say how you are attempting to read the data.

If using a data step

data want (where=(code in ('440', '441','442','443','444','445','446','447')));

     infile ...;

     input ... ;

run;

The same clause should work on the output dataset if using proc import.

If the codes were numeric and not character you could use shorthand  in (440:447) (as well as specific other values or similar groups)

Ask a Question
Discussion stats
  • 1 reply
  • 245 views
  • 0 likes
  • 2 in conversation