SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
njwmeme
Fluorite | Level 6

Hi,

 

I am reading my data source from Excel. It has columns from 1 to 28, 29, 30, 31 and MTD(Month to date). Excel files will have different columns depending on the current month's days.

Will need help on the (keep=) function. Is there any code I can use to keep a range of columns like from 1 to MTD? So it will take whichever columns in between. Columns are numeric and characters

 

Thank You.

Regards.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

First, you need to import the data into a SAS data set.  Afterwards, you can consider how to subset the variables.

 

The easiest way would be if you know the variable name assigned to the first column.  Then you could code:

 

data want;

set have (keep=firstcol--MTD);

run;

 

Of course, you would have to substitute the actual name of the first column for "firstcol".

 

If you don't know the name of the first column, there are ways to get macro language to do this.  But that solution would be far beyond your current knowledge of SAS.  I could program it (not that lengthy), but you would have to take it on faith that it would give the correct answer repeatedly ... so only to be used if necessary.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

First, you need to import the data into a SAS data set.  Afterwards, you can consider how to subset the variables.

 

The easiest way would be if you know the variable name assigned to the first column.  Then you could code:

 

data want;

set have (keep=firstcol--MTD);

run;

 

Of course, you would have to substitute the actual name of the first column for "firstcol".

 

If you don't know the name of the first column, there are ways to get macro language to do this.  But that solution would be far beyond your current knowledge of SAS.  I could program it (not that lengthy), but you would have to take it on faith that it would give the correct answer repeatedly ... so only to be used if necessary.

njwmeme
Fluorite | Level 6
Hi Astounding,

Thanks alot. The '--' code was what I was looking for.
Reeza
Super User

1. Read in your data

2. Transpose it to a long format

3. Implement the filter required which is much easier.

 


@njwmeme wrote:

Hi,

 

I am reading my data source from Excel. It has columns from 1 to 28, 29, 30, 31 and MTD(Month to date). Excel files will have different columns depending on the current month's days.

Will need help on the (keep=) function. Is there any code I can use to keep a range of columns like from 1 to MTD? So it will take whichever columns in between. Columns are numeric and characters

 

Thank You.

Regards.


 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 4850 views
  • 0 likes
  • 3 in conversation