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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: