BookmarkSubscribeRSS Feed
Miracle
Barite | Level 11

Dear All,

May I know how do go from 'have' to 'want' using proc sql?

Thanks a lot.

have
studyid test abc110 1 abc110 2 abc110 3 abc201 1 abc201 2 abc405 1 abc405 2
want
studyid test n abc110 1 1 abc110 2 1 abc110 3 1 abc201 1 2 abc201 2 2 abc405 1 3 abc405 2 3

 

5 REPLIES 5
Kurt_Bremser
Super User

The task defines the tool, so you use the data step for this:

data want;
set have;
by studyid;
if first.studyid then n + 1;
run;

No need to code yourself to insanity when there's such a simple solution.

Miracle
Barite | Level 11

Thanks @Kurt_Bremser  for your solution using datastep.
But I need to perform this manipulation using proc sql.
BTW, this is not homework. I try to use proc sql more for my work now.
Thanks a lot.

PaigeMiller
Diamond | Level 26

@Miracle wrote:


But I need to perform this manipulation using proc sql.


Really a bad idea. Use a DATA step. Don't listen to me, listen to @Kurt_Bremser , he knows.

--
Paige Miller
Kurt_Bremser
Super User

@Miracle wrote:

I try to use proc sql more for my work now.


Mastery of a tool also means knowing when not to use it.

SQL is very useful for a lot of things, but using it here, and in a production environment(!), would simply be stupid. The next one to maintain that code will come after you with murder in their eyes.

Miracle
Barite | Level 11

Thanks everyone for the advice. 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 416 views
  • 4 likes
  • 3 in conversation