BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
praveenkotte
Fluorite | Level 6

I've dataset name called sales

I want sort data without using proc and first.var and last.var;

 

 

data tab;

input country;

cards;

1

3

2

5

6

1

5

4

;

run;

 

 

could you please help me out....

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Maybe they just want a computer science guy who know data structure. not a sas or statististic guy.

This kind of question should be given to software developer . not data analysis.

 

data tab;
input country;
cards;
1
3
2
5
6
1
5
4
;
run;

data want;
 set tab end=last;
 array x{99999} _temporary_;
 x{_n_}=country;
 if last then do;
  do i=1 to _n_;
   do j=i+1 to _n_;
    if x{i} gt x{j} then do;
     temp=x{i};x{i}=x{j};x{j}=temp;
    end;
   end;
  end;
  
  do k=1 to _n_;
   country=x{k};output;
  end;
 end;
 keep country;
run;

View solution in original post

5 REPLIES 5
praveenkotte
Fluorite | Level 6

it was one of the interview question that i was asked for..

RW9
Diamond | Level 26 RW9
Diamond | Level 26

"

I want sort data without using proc and first.var and last.var;" - How will first/last help you sort anything?

Use one of the methods developed by experts over years = proc sort, order by.  These are both efficient and simple, and all SAS programmers will be abel to understand your code easily.  

 

Alternatively, get yourself and x86 assembler and write all your code using machine code.

Ksharp
Super User

Maybe they just want a computer science guy who know data structure. not a sas or statististic guy.

This kind of question should be given to software developer . not data analysis.

 

data tab;
input country;
cards;
1
3
2
5
6
1
5
4
;
run;

data want;
 set tab end=last;
 array x{99999} _temporary_;
 x{_n_}=country;
 if last then do;
  do i=1 to _n_;
   do j=i+1 to _n_;
    if x{i} gt x{j} then do;
     temp=x{i};x{i}=x{j};x{j}=temp;
    end;
   end;
  end;
  
  do k=1 to _n_;
   country=x{k};output;
  end;
 end;
 keep country;
run;

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
  • 5 replies
  • 1519 views
  • 2 likes
  • 4 in conversation