BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aanan1417
Quartz | Level 8

i have 10000 variable and i want to keep only 500 variable.

without using keep drop

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@aanan1417 wrote:

i have 10000 variable and i want to keep only 500 variable.

without using keep drop


WHY?

 

The only other method I can think of is to explicitly name each of your columns in a SELECT statement in SQL.

 

proc sql;
create table want as
select name, age 
from sashelp.class;
quit;

If you have naming conventions or patterns you can generate your variable lists dynamically or use variable short cut lists but those cannot be used in SQL.

Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

 

View solution in original post

3 REPLIES 3
Reeza
Super User

@aanan1417 wrote:

i have 10000 variable and i want to keep only 500 variable.

without using keep drop


WHY?

 

The only other method I can think of is to explicitly name each of your columns in a SELECT statement in SQL.

 

proc sql;
create table want as
select name, age 
from sashelp.class;
quit;

If you have naming conventions or patterns you can generate your variable lists dynamically or use variable short cut lists but those cannot be used in SQL.

Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

 

ballardw
Super User

@Reeza wrote:

@aanan1417 wrote:

i have 10000 variable and i want to keep only 500 variable.

without using keep drop


WHY?

 

The only other method I can think of is to explicitly name each of your columns in a SELECT statement in SQL.

 


A real kludgy method is create a separate data set with the desired named variables of the proper types and use Proc Append with Force. Not that I advocate such, but it is a way that meets OP somewhat problematic requirement. Probably way more work than proper variable lists with drop and keep.

 

@aanan1417 could share a proc contents with Order=Varnum output and indicate which variables he wants.

Amir
PROC Star

Hi @aanan1417,

 

To help you, we will need more information, e.g.:

 

  1. Are the variables on a SAS data set, or a csv, or some other file?
  2. Where do you want to output the data to, e.g., a csv file?
  3. What code have you tried so far? Please share any error messages and related code from the log.
  4. What is the reason why you cannot use keep or drop?
  5. Do you have any other special requirements?

 

Edit: If you have a SAS data you could write it out to a file (e.g., proc export) and just read in the information you want from that file, but again the requirement to not use drop or keep, means there is more code (and I/O in this case) than is necessary.

 

 

Thanks & kind regards,

Amir.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 572 views
  • 1 like
  • 4 in conversation