I am getting this error:
Column SomeColumn could not be found in the table/view identified with the correlation name TRANS.
Using this code
proc sql;
CREATE TABLE WORK.Test AS
select
Trans.SomeColumn
from WORK.Joiner AS J
left outer join work.parameterestimatestrans AS Trans
ON J._NAME_ = Trans._NAME_;
run;
I know that SomeColumn is not in the table aliased Trans. However, a left out join should simply return a null (i.e. . in SAS). So I am a bit confused about the non sql sas behaviour. Any ideas?
The error is exactly what should happen. You explicitly named a column in the select that does not exist, so your select statement is useless.
SQL does not automatically create variables with missing values, as the data step does.
@csetzkorn wrote:
Would you mind creating the datastep equivalent please?
It might help if you describe what the output should be. From the code posted it only appears that you want a data set with single variable and all values missing.
Here, I fixed it for you, with a numeric and character missing.
proc sql;
CREATE TABLE WORK.Test AS
select
" " as SomeColumn,
. as NumSomeColumn
from WORK.Joiner AS J
left outer join work.parameterestimatestrans AS Trans
ON J._NAME_ = Trans._NAME_;
run;
I found a solution to my problem. Using:
data work.parameterestimatestrans;
set work.parameterestimatestrans;
NumSomeColumn = coalesce(NumSomeColumn,.);
run;
Will impute the variable should it be missing and the left join picks this up.
What do you mean by
@csetzkorn wrote:
if work.parameterestimatestrans does not exist.
- the dataset does not exist
- or the dataset exists, but there is no matching record in it
- or the column does not exist in the dataset
?
If it doesn't exist the COALESCE doesn't do anything.
It assigns a missing value.
Since the OP has finally stated his/her true intentions, I can say that the data step with coalesce() is the correct solution.
The OP wants to reach a state where the variable will be present, no matter what is in the original dataset.
If the variable is not there, it will be created as missing, if it is there, the values will be preserved.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: