DATA Step, Macro, Functions and more

Sorting of variable

Reply
Occasional Contributor
Posts: 14

Sorting of variable

I have a variable with values
NA - a1 b1 c1 a2 b2 c2 a3 b3

I need a new dataset with new variable sorted and old variable should not be sorted as below
NA - a1 b1 c1 a2 b2 c2 a3 b3
NA1 - a1 a2 a3 b1 b2 b3 c1 c2

Thanks in advance.
Super User
Super User
Posts: 9,799

Re: Sorting of variable

Posted in reply to NagendraBS

Post test data in the form of a datastep!!!

 

What is NA, is it one variable, a set of variables?  If it is one variable, why is it one variable, a variable is to hold one piece of information, hence coding against a variable with multiple pieces of information will be difficult, whereas if each their own its very simple.

data want;
  na1="a1";
  na2="b1";
  na3="c1";
  na4="a2";
  original_na=catx(" ",of na:);
  call sortc(of na:);
run;
Super User
Posts: 10,530

Re: Sorting of variable

Posted in reply to NagendraBS

Do you mean this:

proc sort
  data=have (rename=(NA=NA1))
  out=int
;
by NA1;
run;

data want;
merge
  have
  int
;
run;

?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 2 replies
  • 52 views
  • 0 likes
  • 3 in conversation