Subset the SAS dataset

Reply
New Contributor
Posts: 3

Subset the SAS dataset

Hi All,

I have a dataset which I need to subset from already sas7bdat file for manager. When I write a code for this using Libname to subset, it gives me an error "File name"". Not found.

The following is the code:

LIBNAME new1''Path of the file'';

data one;

DATA new1.one;

set new1.filename;

if position=manager;

proc print;

run;

Kindly assist me.

Respected Advisor
Posts: 4,973

Re: Subset the SAS dataset

Mohammed,

You're going to have to do a lot of the work here.  There's too much that you don't know and would need help with.  Here are a few of the basics to get you started.

The path in a LIBNAME statement should be the path to a folder, not the path to a file.  It's the folder where the SAS data set is stored (or alternatively where a new SAS data set is to be saved).

You only need one DATA statement, not two.  The DATA statement names the data set being created, and the SET statement names the data set being read in.  You will have to research how to use a two-part name to identify permanently saved data sets.

It's likely that you need quotes around 'manager'.  Without quotes, the statement checks whether the variable named POSITION has the same value as the variable named MANAGER.  Whenever something appears in quotes in SAS, spelling and capitalization is important.

Good luck.

Grand Advisor
Posts: 17,332

Re: Subset the SAS dataset


Change the path, from path to the file, to the path of the directory containing the file


LIBNAME new1''Path to the directory containing the SAS file'';


WRONG => Libname new1 'c:\temp\sample.sas7bdat';

CORRECT=> Libname new1 'C:\temp\';


Also for filtering, the value needs to be in quotes and needs to match the case of the data or use a function such as upcase/lowcase to make them all the same.


WRONG =>position = manager

CORRECT => upcase(position) = 'MANAGER'



New Contributor
Posts: 3

Re: Subset the SAS dataset

Hi Reeza,

I did write a code as per your suggestions directing to the file path instead of file name. However, it still gives me an error stating the "Set new1.filename " not found.

Below is the code I wrote:

LIBNAME new1''Path of the directory containing the file";

DATA one; ( created a temporary folder)

Set new1.filename;

if position="MANAGER";

Proc print;

run;'

It gives me an errorOutput error.PNG

Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Subset the SAS dataset

You have a typo in the libname statement, look at the first note in your log.  Missing space after new1 possibly, or that folder does not exist.

Ask a Question
Discussion stats
  • 4 replies
  • 292 views
  • 6 likes
  • 4 in conversation