BookmarkSubscribeRSS Feed
zsmith93
Calcite | Level 5

So my goal is to take two data sets and make an output table in which I take the difference between two fields while also keeping one of the fields from both data sets that correspond to their records.

 

E.g., import(major, median, ...) and import1(name, region, strtMedian, ...)

 

data Diff_Acct_Cali;
   set work.accounting_major, work.cali_region;
   difference = (accounting_major.median - cali_region.startMedian);
   keep accounting_major.major cali_region.name difference;
run;

 

What I'm trying to do is take a record from work.accounting_major and work.cali_region particularly median and startMedian respectively. Save the difference into a new record that has the field major from accounting_major and name from cali_region.

 

All that gets outputted is a table with a column labeled difference with nothing in it. What am I doing wrong?

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Since we don't have your data, all we can do is clean up your code. Then it's up to you to get it to work.

 

 

set work.accounting_major, work.cali_region;

probably should be

 

 

merge work.accounting_major work.cali_region;
by id_variable; /* MAY NOT BE NEEDED, but we don't have your data to know for sure */

Merges are usually needed if you want to do a subtraction of a variable in one data set from a variable in another data set.

 

 

 

Then, 

 

difference = (accounting_major.median - cali_region.startMedian);

is a problem as well, you can't use SQL syntax mixed in with DATA step syntax. You need to use only data step syntax. Most likely you want:

 

difference = median - startmedian;

but again, I don't have your data.

 

You might want to work through some beginner examples and view some beginner tutorials on SAS, as these are rather basic errors.

--
Paige Miller
zsmith93
Calcite | Level 5

https://www.kaggle.com/wsj/college-salaries#degrees-that-pay-back.csv

The data sets can be found there. What I'm trying to do is compare the median salary of each major from the degrees-that-pay-back.csv compared to each university in a given region from the salaries-by-region.csv. I'm trying to present this as a bar graph where the y axis is the median salary and the x axis would the universities. Yes I understand this should be very easy but when I run my proc's the process just keeps running indefinitely.

PaigeMiller
Diamond | Level 26

@zsmith93 wrote:

https://www.kaggle.com/wsj/college-salaries#degrees-that-pay-back.csv

but when I run my proc's the process just keeps running indefinitely.


Show us your code, or better yet, the LOG (the entire LOG, not just the errors) by pasting the LOG into the window that appears when you click on the {i} icon.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 3 replies
  • 612 views
  • 0 likes
  • 2 in conversation