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

Hi all,


I am a beginner at SAS. In my project, tried to run a piece of code to programmatically create a data set from an existing one with a new variable that has a value conditional on another existing variable. This is the code I ran:

 

data EMPDUP;
set EMWS1.Ids3_DATA;
MED_DUM = .;
If MEDV >= 25 THEN MED_DUM = 1;
run;

 

It runs the SAS code node fine, but I just can't seem to find where this EMPDUP dataset is. Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
AndrewHowell
Moderator

Unless you're playing around with some advanced SAS options, when you create a table without a library reference, the default location for the newly created table is the WORK library.

 

So the following two statements are effectively identical:

 

data EMPDUP;
	set EMWS1.Ids3_DATA;
	MED_DUM = .;
	If MEDV >= 25 THEN MED_DUM = 1;
run;

data WORK.EMPDUP;
	set EMWS1.Ids3_DATA;
	MED_DUM = .;
	If MEDV >= 25 THEN MED_DUM = 1;
run;

As to where your table is PHYSICALLY located, run the following code to reveal the location of your WORK library location (Note: This location will most likely be different every time you run SAS)

 

%put %sysfunc(pathname(WORK));

View solution in original post

5 REPLIES 5
AndrewHowell
Moderator

Unless you're playing around with some advanced SAS options, when you create a table without a library reference, the default location for the newly created table is the WORK library.

 

So the following two statements are effectively identical:

 

data EMPDUP;
	set EMWS1.Ids3_DATA;
	MED_DUM = .;
	If MEDV >= 25 THEN MED_DUM = 1;
run;

data WORK.EMPDUP;
	set EMWS1.Ids3_DATA;
	MED_DUM = .;
	If MEDV >= 25 THEN MED_DUM = 1;
run;

As to where your table is PHYSICALLY located, run the following code to reveal the location of your WORK library location (Note: This location will most likely be different every time you run SAS)

 

%put %sysfunc(pathname(WORK));
davidzhang8828
Fluorite | Level 6

Hi Andrew,

 

This was the perfect answer. I ran the filepath code to find where the dataset was and moved it into the project. It imported as a data source perfectly.

 

Thanks again!

Reeza
Super User

Interestingly, that was not the code you posted on SO.

 

Here, you're using a library, EMWS1, as your source data. If you use the same library for the output data, is it in your project automatically?

 

data EMWS1.EMPDUP;
set EMWS1.Ids3_DATA;
MED_DUM = .;
If MEDV >= 25 THEN MED_DUM = 1;
run;
davidzhang8828
Fluorite | Level 6

Hi Reeza,

 

Haha, it's great seeing you around here too! 🙂 

 

Yeah, I had a misunderstanding of how to use the DATA statement. I didn't know you had to preface it for the relevant library. The example I put on SO was with generic names to make it simpler.

 

Thanks again for all the help. Project is going smoothly! Smiley Happy

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As you learning, I would just like provide some tips.  Look at the code people post here, particularly the formatting, indetation, casing, and not using shorthands.  Code should be readable above all else, then it should be efficient.  So for the code you posted:

data work.empdup;
  set emws1.ids3_data;
  med_dum=.;
  if medv >= 25 then med_dum=1;
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 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
  • 5 replies
  • 1134 views
  • 2 likes
  • 4 in conversation