SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
saikiran_nemani
Obsidian | Level 7

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

5 REPLIES 5
ChrisHemedinger
Community Manager

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

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
SuryaKiran
Meteorite | Level 14

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
TomKari
Onyx | Level 15

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

 

 

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!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 13044 views
  • 1 like
  • 6 in conversation