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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 10776 views
  • 1 like
  • 6 in conversation