🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-18-2021 12:32 PM
(9559 views)
Hi experts,
I'm new to sql, I came across a sql code but I feel very difficult what it does?
Proc sql;
Cast(sum(week_ending)) as current_4weeks;
Quit;
And I'm not sure about the code. My question is what does the Cast function do?
Any alternative function can I use for it? Bcoz in my SAS studio, I'm not able to run Cast function.
TIA
I'm new to sql, I came across a sql code but I feel very difficult what it does?
Proc sql;
Cast(sum(week_ending)) as current_4weeks;
Quit;
And I'm not sure about the code. My question is what does the Cast function do?
Any alternative function can I use for it? Bcoz in my SAS studio, I'm not able to run Cast function.
TIA
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use PUT/INPUT within PROC SQL or a DATA STEP.
7 REPLIES 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Cast would typically be used to convert data types, which would require specifying the output type in general.
However with the SAS Proc SQL it will throw an error.
8 proc sql; 9 select cast(sum(weight)) as totalweight 10 from sashelp.class; ERROR: Function CAST could not be located. 11 quit;
Proc FEDSQL which is intended for use with non-SAS traditional data sets supports the CAST function
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In other words, can I use put/input function to change the data type in proc sql.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use PUT/INPUT within PROC SQL or a DATA STEP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
FYI - I'd probably mark @ballardw answer as correct, mine is helpful, but his actually answers your initial question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then what is the difference between cast and put/input function??
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SQL is not a single language, Oracles implementation of SQL is different than Microsoft, which is different than DB2.
They can have different functions.
CAST is a valid conversion function in other SQL implementations, but not in SAS PROC SQL.
CAST is a valid function in SAS PROC FEDSQL.
The equivalent functions for CAST in SAS is PUT()/INPUT().
They can have different functions.
CAST is a valid conversion function in other SQL implementations, but not in SAS PROC SQL.
CAST is a valid function in SAS PROC FEDSQL.
The equivalent functions for CAST in SAS is PUT()/INPUT().