05-14-2012 09:44 AM
In the discussion
Combining the same variable on different records into a single variable
you all had given some wonderful suggestions. i went ahead and used LinLin's suggestion. I had the following requirement added.
I had one additional question. Can we have newline to be dynamic?
As in if we do not know the maximum number of rows that can have the same id. Does SAS support dynamic variables.
We have scenarios where newline can be 100, 350 or 500 and could be even more.
05-14-2012 10:13 AM
SAS does not support dynamic variable lengths. You can obtain the same result as dynamic variables by passing the data once to obtain the maximum number of repeats for the newline variable and then using macro programming to set the length for the subsequent step. The downside is that you have to read the data twice.
05-14-2012 11:13 AM
I can creates a dataset with id as the variable , then I can do a count on the maximum occurrence of an id. Once I get this count can I declare the length variable with this count.
For example the max occurrence of an id is 5 and this is stored in countid. Suppose the lenth of the line variable is 50 then new line will be
length newline $countid;
Is this feasible?
05-14-2012 11:59 AM
then the length should be 5*50=250;
you can try something like the code below:
input id line$ 50.;
proc sql noprint;
select max(count)*50 into :countid separated by ' ' from (select count(id) as count from have group by id);
data want(keep=id newline);
length newline $&countid;
by id ;
if last.id then do;output ;
call missing(newline); end;
Message was edited by: Linlin
05-15-2012 12:09 AM
You can set it with the maximum length .
length newline $ 32767 ;
But if the length can't still hold all of the value, then I think you need two or more newline to hold .