Discover More Tips and Techniques on This Blog

How can I convert a numeric date variable to a character variable using PROC SQL?

Helpful documents for Proc SQL:Inside PROC SQL's Query Optimizer


PROC SQL -- The Long and The Short of It

Performance Enhancements to PROC SQL in Version 7 of the SAS® System


Using the SAS/ACCESS Libname Technology to Get Improvements in Performance and Optimizations in SAS/SQL Queries

How can I convert a numeric date variable to a character variable using PROC SQL?The PUT function can be used within PROC SQL to create a character date string from a numeric SAS date value. data numdate;


******************************************************;
data numdate;
date=TODAY();
run;

proc sql;create table new as select PUT(date,date9.)
as newdate from numdate;
quit;

************************************************************;source:
www.support.sas.com
How can I convert a character date variable to a numeric date variable with PROC SQL?

The INPUT function can be used within PROC SQL to create a numeric date variable from a character date string.
****************************************************************;
data chardate;
date='08/30/2006';
run;


proc sql;
create table new as select INPUT(date,mmddyy10.)
as newdate format=mmddyy10. from chardate;
quit;


****************************************************************;
source: http://www.support.sas.com/ Usage Note 24527...

CLASS Statement

When should I put a variable in the CLASS statement? What does the CLASS statement do?

The CLASS statement is used to indicate which variables in the model are categorical variables. In most modeling procedures, such a variable is then treated as a nominal (unordered) categorical predictor variable. A set of numeric indicator ("dummy") variables is created internally to represent the levels of the variable. Because the indicator variables are used for fitting the model, the original variable does not need to be numeric. The resulting model has multiple parameter estimates (one for each indicator variable). Each parameter compares one level of the predictor with a reference level, typically the last level in sorted order. A joint test of all the estimated parameters for the predictor is a test for any differences among the levels and is therefore a test of the predictor's overall effect.

In contrast, a variable name that appears in the MODEL statement but not in the CLASS statement is treated as a continuous predictor variable. The variable itself is used in fitting the model. Therefore, the variable must be a numeric SAS variable and should be continuous or at least be ordered with assigned numeric scores. The resulting model typically has one parameter estimate (there might be more for models with multiple response variables or functions) that estimates the linear effect of the predictor.

Note that if the predictor was unordered, it would not be useful to test for its "linear" effect because you cannot talk about the effect of "increasing" an unordered variable. So, all nominal, categorical variables should be listed in the CLASS statement. On the other hand, you might choose to ignore the ordering in a continuous predictor variable and treat it as a nominal predictor by specifying it in the CLASS statement. But remember that a parameter will be added to the model for each additional level of the variable and this could result in a very large model if the variable has many distinct values in the data set.

Some procedures (such as PROC LOGISTIC) offer many options in the CLASS statement that enable you to designate how the internally generated variables are coded. Each coding method imposes a different interpretation on the estimated parameters. For instance, the GLM (or indicator or dummy) coding method that was mentioned earlier creates parameter estimates that compare the effect of each level to the effect of the reference level. Another coding method for nominal predictors is effects coding, which results in parameter estimates that compare the effect of each level to the average effect of all the levels. There is a coding method appropriate for variables that are ordinal but with unknown spacing between the levels. And there is a coding method for continuous variables that decomposes the variable's effect into linear, quadratic, cubic, and other components.

source:
www.support.sas.com

Disclosure:

In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers. My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.