Desktop productivity for business analysts and programmers

How to create a variable with values as 1 in proc sql

Reply
Occasional Contributor
Posts: 18

How to create a variable with values as 1 in proc sql

How to create a variable with values as 1 in proc sql

Community Manager
Posts: 3,382

Re: How to create a variable with values as 1 in proc sql

Posted in reply to saikiran_nemani

I'm guessing that you want to create dummy variables to prep data for modeling.

 

You can do this with simple boolean expressions.  Example:

 

proc sql;
 create table dummy_class
  as select name, age,
   sex="M" as isMale,
   sex="F" as isFemale
 from sashelp.class;
quit;

dummy.png

Super User
Super User
Posts: 9,427

Re: How to create a variable with values as 1 in proc sql

Posted in reply to saikiran_nemani

Please post a clear example of what you have - test data in the form of a datastep - and what you want out at the end.  Otherwise you will not get good answers.  Simply:

proc sql;
  create table want as
  select *,
         1 as new_var
  from   have;
quit;
Valued Guide
Posts: 560

Re: How to create a variable with values as 1 in proc sql

Posted in reply to saikiran_nemani

If your trying to create a new variable on a condition on other variable then you can use a case expression.

proc sql;
select *, Case  when Age>15 then 1 
				when Age<13 then 0
			else 2 end as new_var
	from sashelp.class;
quit;
Thanks,
Suryakiran
Super User
Posts: 23,320

Re: How to create a variable with values as 1 in proc sql

Posted in reply to saikiran_nemani
PROC Star
Posts: 1,288

Re: How to create a variable with values as 1 in proc sql

Posted in reply to saikiran_nemani

If you just want a variable that's always 1:

 

proc sql noprint;
	create table want as select name,
		1 as OneVar
	from sashelp.class;
quit;

 

Tom

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 108 views
  • 1 like
  • 6 in conversation