Proc Sql Case When Multiple Variables
Similar to an if then construct in the data step a case expression uses one or more when then clause s to conditionally process some but not all the rows in a table.
Proc sql case when multiple variables. Variables in sql procedures are defined by using the declare statement. Proc sql produces six automatic macro variables sqlobs sqlrc sqloops sqlexitcode sqlxrc and sqlxmsg to help you troubleshoot your programs. Select from mylib outdata. For more information see using the proc sql automatic macro variables.
Multiple variables with case in proc sql. When 21 daysdiff 30 then 21 30. The case expression in the second proc sql step is a shorthand method that is useful when all the comparisons are with the same column. Selecting all variables from the data set proc sql.
The following two proc sql steps show two equivalent case expressions that create a character column with the strings in the then clause. Creating macro variables in proc sql. For creating one variable the code which works fine is. When daysdiff 10 then 0 10.
Selecting specific variables from the data set in the select clause multiple columns are separated by commas. Create table mom 2 as select case when mom id in select mom id from mom 1 where compress dx code between xx xx and xx xx then 1 else 0 end as diabetes from mom 1. Values can be assigned to variables using the set statement or the select into statement or as a default value when the variable is declared. Now i have multiple dx code variables associated with multiple visits.
When 11 daysdiff 20 then 11 20. The macros variables that are defined by sas are called automatic macro variables. The sql procedure supports conditionally selecting result values from rows in a table or view in the form of a case expression. You can use the asterisk character to select all variables from a dataset.
Previously i used the following code to create a variable for diabetes. Sorting data the order by clause returns. The case expression in the second proc sql step is a shorthand method that is useful when all the comparisons are with the same column. In proc sql you must name each variable you want in the output dataset.
Posted 08 27 2010 05 54 am 20583 views is it possible to create more than variable using case in proc sql.