BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
DATA multdat;
FORMAT date mmddyy10.;
INPUT id $ date mmddyy10. T1 T2 T3 T4 T5 T6;
CARDS;
A1 11/01/2004 223 204 195 196 197 200
A2 11/01/2004 211 192 183 196 197 200
;
run;


DATA univdat;
SET multdat;
ARRAY TEST{*} T1-T6;
KEEP id date RESULT;
DO i = 1 to dim(TEST);
RESULT=TEST(i);
OUTPUT;
END;
RUN;

The above code works fine as long as the number of variables for array name test remain the same.There could be less or more variables. next month I may get only 3 values T1 to T3? or I may get more than 6? How to assign an upper bound to the variable T?
3 REPLIES 3
Flip
Fluorite | Level 6
How about something like this?

Proc sql;
select max(input(subtr(name, 2), best.) into : tlim
from dictionary.columns where libname = "WORK" and memname = "MULTDAT"
and substr(name , 1,1) = 'T';

then use &tlim


Warning: code off the top of my head may contain errors;}
SASPhile
Quartz | Level 8
Flip,
I tried this and it worked:

DATA multdat;
FORMAT date mmddyy10.;
INPUT id $ date mmddyy10. T1 T2 T3 T4 T5 T6 T7;
CARDS;
A1 11/01/2004 223 204 195 196 197 200 300
A2 11/01/2004 211 192 183 196 197 200 300
;
run;
proc sql;
select count(*) into:up from sashelp.vcolumn where libname='WORK' and memname='MULTDAT' and
name like '%T%';
quit;
%put &up.;
%macro try;
DATA univdat;
SET multdat;

ARRAY TEST{*} T1-%sysfunc(compress(T&up.));
KEEP id date RESULT;
DO i = 1 to dim(TEST);
RESULT=TEST(i);
OUTPUT;
END;
RUN;
%mend try;
%try;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Consider that if you have control over the SAS variables named in your DATA step and SAS dataset, you can define an ARRAY statement with a variable prefix, such as:

ARRAY ATNNN (*) T: ;

but you would not be able to have any other variables (not in the array nor of a different SAS variable type) defined in the SAS dataset.

Clearly this technique may or may not apply, but it is possible with some programming instances.

Scott Barry
SBBWorks, Inc.

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!

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
  • 897 views
  • 0 likes
  • 3 in conversation