How to make a new dataset which will be having only distict values of required variables from a dataset?

Reply
Occasional Contributor
Posts: 18

How to make a new dataset which will be having only distict values of required variables from a dataset?

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.)

Trusted Advisor
Posts: 1,913

Re: %do loop inside proc sql

Posted in reply to bonzybuddy

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.

Occasional Contributor
Posts: 18

Re: %do loop inside proc sql

Posted in reply to PaigeMiller

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.  

Trusted Advisor
Posts: 1,913

Re: %do loop inside proc sql

Posted in reply to bonzybuddy

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.

Occasional Contributor
Posts: 18

Re: %do loop inside proc sql

Posted in reply to PaigeMiller

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;.

Trusted Advisor
Posts: 1,913

Re: %do loop inside proc sql

Posted in reply to bonzybuddy

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

Occasional Contributor
Posts: 18

Re: %do loop inside proc sql

Posted in reply to PaigeMiller

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

Anyways, Thanks man.

Smiley Happy

Super User
Posts: 19,770

Re: %do loop inside proc sql

Posted in reply to bonzybuddy

Post some example with data. 

Occasional Contributor
Posts: 7

Re: How to make a new dataset which will be having only distict values of required variables from a dataset?

Posted in reply to bonzybuddy

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;

Ask a Question
Discussion stats
  • 8 replies
  • 267 views
  • 3 likes
  • 4 in conversation