Hi:
Pardon my confusion.
Why did you post data with an ORDER and go on and on about needing a new ORDER variable if your data does not have an ORDER variable in the first place?
Of course, when you read the data, you could make the original order variable by assigning _N_ to the ORDER variable and then go through the rest of the steps as previously shown by other participants.
cynthia
Hello @Cynthia_sas,
The data which I wrote, is an input table so it can change not because of me. That is the reason why also I want to ask what if Order variable is not contained, question.
The method which I did as below. I think you also suggested me the sample method. If I understood incorrect, I'm sorry 😞
Data Want;
Set Pre_Want;
Order=_N_;
Run;
Proc Sql;
Create Table Want As
Select Dataset
,Preffix
,Case
When Upcase(Preffix)="DEV" Then -5
WHEN Upcase(Preffix)="REC" Then 99999
Else Order
End AS Order
From Have
Order By Order;
Quit;
Data Want2;
Set Want;
Order=_N_;
Run;
Thank you
Thank you so much for your warm approach .Your approach and your reccommendation are much appreciated.
At this moment, learning Hash is also far from me, it seems difficult but I can guess how powerful Hash code is . I need a time to converge it.
About your second reccomandation you are totally right. This statement is what I'm facing nowadays -> that generally is a sign that the requirements are still in flux and that you are going to be constantly fiddling with/modifying your program to suit the data they send you.
Thank you
Data Have; Length DataSet $ 32 Preffix $ 32 Order 8; Infile Datalines Missover; Input DataSet Preffix Order; Datalines; Have Mdl 1 Want Dev 2 Last Rec 3 Want2 Val2 4 Desired Val 5 Have2 Mdl2 6 ; Run; data want; if _n_=1 then do; if 0 then set have(rename=(Order=_Order Preffix=_Preffix)); declare hash h(dataset:'have(rename=(Order=_Order Preffix=_Preffix) where=(_Preffix in ("Dev" "Rec")))'); h.definekey('_Preffix'); h.definedata('_Order'); h.definedone(); end; set have nobs=nobs end=last; if _n_=1 then do; _Preffix='Dev'; h.find(); Order=_Order; end; if Preffix='Dev' then Order=1; if Preffix='Rec' then Order=nobs; if last then do; _Preffix='Rec'; h.find(); Order=_Order; end; drop _:; run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.