BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Quadraaa
Calcite | Level 5

Wow, gentlemen, I am really surprised with how detailed and useful your answers are Smiley Happy  When I see these tricks I have two contradictory feelings: 1) I feel upset about my poor knowledge of SAS and 2) I feel glad that there are so many interesting things to learnSmiley Happy

Thanks a lot to all of you.

FriedEgg
SAS Employee

I have to send a kudos to SASJedi as well for going well beyond in his response what I would consider necessary and giving you not just an answer to point you in a direction but a real process to utilize.

slsnx2
Calcite | Level 5

I have to share my code:

I know it's a closed topic but I think this could be useful.

/************************************************************************************/

/* Descripcion general del programa:                                                    */

/* Suma las variables numericas de una tabla, sin especificar nombres. */

/* Autor             : Saul Sanchez Sánchez                                             */

/************************************************************************************/

data a;

do i=1 to 100;

  a=abs(int(rand('NORMAL')*1000));

  b=abs(int(rand('NORMAL')*1000));

  c=abs(int(rand('NORMAL')*1000));

  cl='a'||substr(left(compress(i)),1,1);

  output;

end;

run;

data vars(where=(type='N'));

   length name $ 8 type $ 1;

   drop dsid i num rc;

   dsid=open("work.a","i");

   num=attrn(dsid,"nvars");

   do i=1 to num;

      name=varname(dsid,i);

      type=vartype(dsid,i);

      output;

   end;

   rc=close(dsid);

run;

data vars(keep=function);

set vars;

function='sum('||compress(name)||') as '||compress(name);

run;

proc sql;

select function into :function separated by ','

from vars;

quit;

%put &function;

proc sql;

create table b as

select cl, &function

from a

group by 1;

run;

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
  • 17 replies
  • 26179 views
  • 6 likes
  • 7 in conversation