BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChanceTGardener
SAS Employee

An alternative approach that avoids combining a DATA step and PROC SQL is to perform the merge in PROC IML (SAS's Interactive Matrix Language). 

 

options fullstimer;
proc iml;
  N = 10;

  /* create a column vector where element 1 = 1, element 2 = 2,..., element N = N */
  i = t(1:N);

  /* read work.have into a matrix */
  use work.have;
   read all var {"i" "c"} into x;
  close work.have;

  /* populate Nx1 vector of missing values */
  c = j(N,1,.);

  /* for intersecting values in {1..N} and the first column in x (i.e., column i from the work.have data set), replace 
the missing value with the second column in x (i.e., column c from the work.have data set) */ c[x[,1]] = x[,2]; /* create output data set */ create work.want var {i c}; append; close work.have; quit;

The FULLSTIMER option lists performance metrics to the log, and is helpful when comparing multiple competing approaches. Below are the results from my desktop version. 

 

NOTE: The data set WORK.WANT has 10 observations and 2 variables.
NOTE: PROCEDURE IML used (Total process time):
      real time           0.02 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              582.78k
      OS Memory          21360.00k

 

To your point (3) above, this is one alternative to the DATA step + SQL procedure approach that combines everything into one procedure, but it's unclear which is more efficient on your real data. The FULLSTIMER will help you test that.  

Reeza
Super User

Brute force manual method:

 

proc sql;
create table integers
(num int);
insert into integers values(0);
insert into integers values(1);
insert into integers values(2);
insert into integers values(3);
insert into integers values(4);
insert into integers values(5);
insert into integers values(6);
insert into integers values(7);
insert into integers values(8);
insert into integers values(9);
quit;

proc sql;
create table want as
select ones.num + tens.num*10 + hundreds.num*100 as total
from integers as ones, integers as tens, integers as hundreds
having total < 130
order by 1;
quit;

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
  • 16 replies
  • 2775 views
  • 12 likes
  • 7 in conversation