BookmarkSubscribeRSS Feed
bonzybuddy
Calcite | Level 5

How to make a new dataset which will be having only distict values of required variables from a dataset? (using proc sql, if not possible then datastep.)

8 REPLIES 8
PaigeMiller
Diamond | Level 26

You will get the word "select" six times, the word "from" six times and the word "where" six times, plus of course the text in between six times.

That doesn't sound like what you want.

&sometext is not defined

None of this will work unless it is inside a macro, I hope you realize that

Your variables will be named var1_var, var2_var, ... (is that really what you want?) and each will be identical to the others because each time you are selecting distinct var1 from the same data set.

Not sure exactly what you want to obtain in this example ... in fact, its not even clear why you need a macro here unless the number 6 can change from run to run.

So basically, I don't understand what you are trying to do, and I think a bit of a description would be necessary before we could advise further.

--
Paige Miller
bonzybuddy
Calcite | Level 5

Yes all this things are inside a macro. I just gave a rough example.

Bsically I want to create a dataset1 to which I want to add variables with unique values from another dataset2 with "WHERE" conditing. The WHERE condition itself gets values from a macro variable.  

PaigeMiller
Diamond | Level 26

Perhaps you could write out a small example without macros to show me what you want to achieve. Because as stated, it seems like you are using the same var1 and dataset1 in each loop through the macro, which makes no sense, you will get the same results in each column.

--
Paige Miller
bonzybuddy
Calcite | Level 5

OK. Explaining you otherway,

    

How to make a new dataset which will be having only distict values of required variables from a dataset? (using proc sql, if not possible then datastep.)

I hope this makes some sense. If not I will write steps;.

PaigeMiller
Diamond | Level 26

As far as I know, you'd have to create a data set separately for each required variable.

SQL doesn't really work if var1 has 12 distinct values and var2 has 5 distinct values, unless you want (possibly) 60 unique combinations of var1 and var2

--
Paige Miller
bonzybuddy
Calcite | Level 5

May be if someone can comeup with something or using datastep.

Anyways, Thanks man.

Smiley Happy

Reeza
Super User

Post some example with data. 

ChandraReddy
Calcite | Level 5

To get distinct varibale values, you may try the simple code:

Proc sql;

     select distinct var1,var2,var3,var4,var5,var6

     from dset1

     where condt1;

quit;

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
  • 8 replies
  • 743 views
  • 3 likes
  • 4 in conversation