SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Pooja98
Fluorite | Level 6
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
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You can use PUT/INPUT within PROC SQL or a DATA STEP.

View solution in original post

7 REPLIES 7
ballardw
Super User

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

 

Pooja98
Fluorite | Level 6
In other words, can I use put/input function to change the data type in proc sql.
Reeza
Super User
You can use PUT/INPUT within PROC SQL or a DATA STEP.
Pooja98
Fluorite | Level 6
Thanks a lot
Reeza
Super User
FYI - I'd probably mark @ballardw answer as correct, mine is helpful, but his actually answers your initial question.
Pooja98
Fluorite | Level 6
Then what is the difference between cast and put/input function??
Reeza
Super User
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().

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 9560 views
  • 1 like
  • 3 in conversation