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

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 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
  • 8086 views
  • 0 likes
  • 3 in conversation