BookmarkSubscribeRSS Feed
Ashwini
Calcite | Level 5

There are 100 variable in a dataset .I want to select  70 variable with out change any change in dataset by using macro code .
Kindly help me

Regards
Ashwini

7 REPLIES 7
Ksharp
Super User

You can use colon operation to select some variables started with the same characters.

data want;

set have(keep= abc: );

run;

If your logic is more complicated then use dictionary table columns and LIKE operation to push the variables you need into a macro variable.

Ksharp

Ashwini
Calcite | Level 5

Dear Ksharp,

Is the any macro code or macro statement to do the same query.

Thanks,

Regards,

Ashwini

Ksharp
Super User

What does your dataset look like ?

and what type of variables do you want to pull out?

You should post an example, then someone will help you .

Ksharp

Ashwini
Calcite | Level 5

Dear Ksharp,

My dataset contain 100 variable .It is contain both character and numeric variable.So I have to keep 70 variable out of 100 variable.Is there any way to create a dataset using macro code with out using keep and drop statement.

Regards,

Ashwini

Ksharp
Super User

Hi.

I think Answer is Yes.

Could you post an example?  Like

I have a table look like:

name     sex    age    weight     height

Patrick   M       25       65            121.2

..............

I want to pull out sex and height.

You 'd better to illustrate the logic of pulling out . Like

I want to pull out 2th,5th variables.

Ksharp

Ashwini
Calcite | Level 5

Dear Ksharp,

I have an data set contain colomn A , B , C, D, E , F , G , H...........Z The required data set is contain only 3 colomn like A,C,G,K ,O, P  .Pls write code using macro code .

Regards,

Ashwini

Ksharp
Super User

I don't understand what your logic is when you pull out some variables?

Why you choose

A,C,G,K ,O, P

not choose

B,D,E,F   ?

Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1691 views
  • 0 likes
  • 2 in conversation