BookmarkSubscribeRSS Feed
changxuosu
Quartz | Level 8

Hi SAS fellows,

 

Say I have an excel with data in cell A1 to Z100.

If I want to import only column A-B, and D-Z

How can I skip column C?

 

would anyone know some code like this will work?

 

proc import datafile="&econ_locat.&file." out=econfile dbms=xlsx replace;

range="Sheet1$A1:B100 and Sheet1$D1:Z100";

run;

 

Can anyone help me to edit the code "range="Sheet1$A1:B100 and Sheet1$D1:Z100;" to make it work?

Or other code that would work except that I don't want to use the "Keep = A B D E F G.... Z" option or "drop = C" option  because the column name of C has spaces (it's "Real GDP" so I want to avoid using keep= and drop = options.
(because in excel the variable name has spaces, which brings another problem to solve) 

(I don't want to change it manually in excel either, because there are actually hundreds of variables like this have spaces)

Thanks!!!!

6 REPLIES 6
Tommy1
Quartz | Level 8

I have not tested it, but I assume if the (keep= a b d..) option is available then you could also do (drop = c))

changxuosu
Quartz | Level 8
the problem is that my name has spaces so I want to avoid using keep= and drop = options.
(because in excel the variable name has spaces, which brings another problem to solve)
Tom
Super User Tom
Super User

Does PROC IMPORT allow you to specify a compound range in the RANGE option?  Try using the syntax that works in Excel.

range="Sheet1$A1:B100,Sheet1$D1:Z100";

But why not just drop it from the SAS dataset. 

Do you know the name of the variable that is in the column you don't want?

out=econfile(drop=C)
changxuosu
Quartz | Level 8
thanks!!! I just tried range="Sheet1$A1:B100,Sheet1$D1:Z100"; no luck : (
Tommy1
Quartz | Level 8

Yea I agree with @Tom , why not just bring everything in and then you can always write a quick data step and drop the variable. It not like there is a lot of data here that we need to worry about bringing too much in.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4591 views
  • 3 likes
  • 3 in conversation