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

Hi SAS Helpers!

 

Very basic question for you about using variables in one table with variables in another table. Using SAS university edition. I'm trying to do arithmetic with the mean and standard deviation of a column in order to set another column as a one or zero depending on whether a different column is >= mean() plus std() in order to do some feature engineering, but my code doesn't work as intended. Please assist!

proc import datafile='/folders/myfolders/cross_table_example.xlsx'
	out = new_table
	dbms = xlsx
	replace;

proc sql;
	create table want as
		select mean(Watch)+std(Watch) as OneDev
  		from new_table;
quit;

* Doesn't work as intended. Get column of all ones;
data new_table;
	set new_table want; * sets the row after the last row of data with what's in want?;
	freqWatcher = 1*(Watch>=OneDev);
run;

Thanks for your help ya'll!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I don't see what is the purpose of table mean_dev. But you seem to want:

 

proc sql;
	create table want as
		select *, Watch >= mean(Watch)+std(Watch) as freqWatcher
  		from new_table;
quit;
PG

View solution in original post

5 REPLIES 5
Reeza
Super User
SET stacks the two data sets on top of each other. You want a merge of types but it's different because you want the value to merge with all other rows you have.

I show two methods of doing this here:
https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas
PGStats
Opal | Level 21

I don't see what is the purpose of table mean_dev. But you seem to want:

 

proc sql;
	create table want as
		select *, Watch >= mean(Watch)+std(Watch) as freqWatcher
  		from new_table;
quit;
PG
schlepro
Fluorite | Level 6

I didn't even think of trying to do it all in SQL. I feel a little sheepish. My bad on mean_dev. I used old junk data to build the post and included more than I needed. I edited the post, but without explanation, so it might have been a little confusing.

 

Follow Up question. How would you put freqWatcher in new_table using native/base SAS? Is that where merge would come in?

 

Cheers!

schlepro
Fluorite | Level 6

Ah, I just tried:

data new_table;
	merge new_table want;
run;

and got exactly what I was looking for. Cool. Thanks for your help ya'll!

 

Cheers!

Reeza
Super User
No, that won't work. Check the link I posted to explain how you would need to do it. That would only bring the value to the first row of the data set but if you only have one I guess that's fine.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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