0

I want to put multiple observations into an own macro variable. I would do this by using select into :obs1 - :obs4, however, as count of observations can differ, i would like to dynamize the range and my code looks like this:

proc sql;
    create table segments as select distinct substr(name,1,6) as segment from dictionary.columns
    where libname = 'WORK' and memname = 'ALL_CCFS' and name ne 'MONTH';
run;

proc sql noprint;
    select count(*) into: count from segments;
run;

proc sql noprint;
    select segment into :segment_1 - :segment_&count. from dictionary.columns;
run;

However, this doesn't seem to work... any suggestions? Thank you!

Niels
  • 141
  • 8

1 Answers1

2
  • Leave last value empty/blank and SAS will create them automatically
  • Set it to an absurdly large number and SAS will only use what's required
  • Use a data step to create it where you can dynamically increment your number (not shown).

    proc sql noprint;
    select segment into :segment_1 - 
    from dictionary.columns;
    run;
    
    
    proc sql noprint;
    select segment into :segment_1 - :segment_999
    from dictionary.columns;
    run;
    
Reeza
  • 20,510
  • 4
  • 21
  • 38
  • 2
    And save the automatic macro variable SQLOBS into your own macro variable (COUNT for example) to remember how many were created. – Tom May 20 '20 at 16:05