SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
stephanicurry
Obsidian | Level 7

Hey everyone! I succesfully created a SAS table with the code below but what I need/want to do now is add another column/variable that is equal to variables One - Two. Help please!

 

proc sql;
create table work.combined as


select
a. Number,
a. County,
a. Counts,
a. Sickness,
a. One,
a. OverallSickness,
b. Number,
b. Two


from
today a,
yesterday b


where
a.Number = b.Number;
quit;

2 REPLIES 2
Tom
Super User Tom
Super User

In general you don't add variables to an existing dataset.

Just make a new dataset. Simple in regular SAS code.

data new_table;
  set combined;
  new_var=one-two;
run;

Or if you want to stick with SQL syntax.

proc sql;
create table new_table as
  select *,one-two as new_var
  from combined
;
quit;

Or just make it when you make the dataset.

proc sql;
create table work.combined as
select
 a.Number
,a.County
,a.Counts
,a.Sickness
,a.One
,a.OverallSickness
,b.Number
,b.Two
,a.One - b.Two as new_var
from today a
   , yesterday b
where a.Number = b.Number
;
quit;
stephanicurry
Obsidian | Level 7
Thanks so much! This was exactly what I needed 🙂

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 833 views
  • 1 like
  • 2 in conversation