BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

Hi All,

Can anyone tell me if I can use 'sort', 'rename' and 'where' command during the data import stage (in another word during data step)?

I want to:

sort them by Emp_ID; and

rename as Name=Student_name; and

import observations where Student_name<>'';

Here is my initial code that I wrote without any of the above condition.


proc import datafile="E:\data_nonsort.xlsx"

dbms=xlsx replace

out=data_sort (keep = Emp_ID Name);

sheet='test';

run;

Thanks and I much appreciate your help,

1 ACCEPTED SOLUTION

Accepted Solutions
dcruik
Lapis Lazuli | Level 10

You can rename your variable Name by modifying your import procedure like so:

proc import datafile="E:\data_nonsort.xlsx"

dbms=xlsx replace

out=data_sort (rename=(Name=Student_name) keep=Emp_ID Name);

sheet='test';

run;

I believe filtering and sorting will have to be done in a separate sort procedure after you import the file into a SAS data set.

Hope that helps.

View solution in original post

2 REPLIES 2
dcruik
Lapis Lazuli | Level 10

You can rename your variable Name by modifying your import procedure like so:

proc import datafile="E:\data_nonsort.xlsx"

dbms=xlsx replace

out=data_sort (rename=(Name=Student_name) keep=Emp_ID Name);

sheet='test';

run;

I believe filtering and sorting will have to be done in a separate sort procedure after you import the file into a SAS data set.

Hope that helps.

Ksharp
Super User

Try to use index= option to sort dataset.

proc import datafile="E:\data_nonsort.xlsx"

dbms=xlsx replace

out=data_sort (rename=(Name=Student_name) keep=Emp_ID Name index=(name)  where=(age gt 12));

sheet='test';

run;

Xia Keshan

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 8051 views
  • 0 likes
  • 3 in conversation