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-2024.png

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.

 

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
  • 6 replies
  • 3528 views
  • 3 likes
  • 3 in conversation