BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

I want the newly created variable "combi" to hold the complete string, but it cuts off at length 8.

 

proc cas;
   session mysession;
   simple.topk /                           
      inputs={"from_gama_agg", "combi"}, topk=5 bottomk=0  aggregator="n"     
      table={
         name="LONGDRIVE_TS", CASLIB="onair"
         where="_FECFACTU=_FULTPATA", 
         computedVars={{name="combi", format='$char44.'}},
         computedVarsProgram="combi=ifc(modsermt in ('D1' 'D2'), 'Mto & desgaste', 'Mto')",                     
         groupBy={"from_brand"}};
run;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
Ammonite | Level 13

This can be fixed by adding a LENGTH statement to your COMPUTEDVARSPROGRAM, something like this:

proc cas;
   session mysession;
   simple.topk /                           
      inputs={"from_gama_agg", "combi"}, topk=5 bottomk=0  aggregator="n"     
      table={
         name="LONGDRIVE_TS", CASLIB="onair"
         where="_FECFACTU=_FULTPATA", 
         computedVars={{name="combi", format='$char44.'}},
         computedVarsProgram="length combi varchar(44); combi=ifc(modsermt in ('D1' 'D2'), 'Mto & desgaste', 'Mto')",                     
         groupBy={"from_brand"}};
run;
quit;

 

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

2 REPLIES 2
SASJedi
Ammonite | Level 13

This can be fixed by adding a LENGTH statement to your COMPUTEDVARSPROGRAM, something like this:

proc cas;
   session mysession;
   simple.topk /                           
      inputs={"from_gama_agg", "combi"}, topk=5 bottomk=0  aggregator="n"     
      table={
         name="LONGDRIVE_TS", CASLIB="onair"
         where="_FECFACTU=_FULTPATA", 
         computedVars={{name="combi", format='$char44.'}},
         computedVarsProgram="length combi varchar(44); combi=ifc(modsermt in ('D1' 'D2'), 'Mto & desgaste', 'Mto')",                     
         groupBy={"from_brand"}};
run;
quit;

 

Check out my Jedi SAS Tricks for SAS Users
Tom
Super User Tom
Super User

Is there some reason you attached the $CHAR format to the variable?  Does it have leading spaces that you want SAS to preserve when it prints the values?

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 925 views
  • 0 likes
  • 3 in conversation