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!
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;
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;
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!
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!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.