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?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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