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

i am rewriting the question posted previously in new post.

 

i have following lookup table that as code and description. i have approximately 80 rows in lookup table.

 

 CodeDescription
1abc         1-this is for value a
2bgcbs     2-contact customer
3jfhfg        3-wait for response
4shdg        4-should be ready
5mi5-made indoor
80ni6-not indoor

 

 i have created Combined Codes column using array. i am trying to convert Combined Codes column like Combined description by applying format from above lookup table. Combined Codes are seperated by ' : ' .

 

Customer nameabc_checkbgcbs _checkjfhfg_check        shdg_check        mi_checkni_checkCombined CodesCombined Description
aabc          jfhfg         mi abc  : jfhfg : mi1-this is for value a : 3-wait for response :  5-made indoor
b   shdg         nishdg : ni4-should be ready :  6-not indoor
c bgcbs       mi bgcbs : mi 2-contact customer : 5-made indoor
dabc          jfhfg           abc  : jfhfg        1-this is for value a :   3-wait for response
e bgcbs      shdg        mi bgcbs : shdg : mi 2-contact customer : 4- should be ready : 5-made indoor
f   shdg         nishdg : ni4-should be ready :  6-not indoor

 

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Please examine:

data cntlin;
   set codes;
   start=code;
   end=code;
   label=description;
   Fmtname= 'abc';
   type='C';
;
run;

proc format library=work cntlin=cntlin;
run;

data want;
   set have;
   array v abc_check bgcbs_check jfhfg_check  shdg_check  mi_check ni_check ;
   length combineddescription $ 200;
   do i=1 to dim(v);
      combineddescription = catx(':',combineddescription,put(v[i],$abc.));
   end;
run;

The CNTLIN data set used by Proc format will require several variables and the names must be: Fmtname, start, end, label and type.

 

Fmtname is the name of the format you want to use, start is the beginning value for a range, end is the end value for a range with a single valid then set both the value, label is the text to display and type is designate the format type C=Character or N=Numeric.

there are other options but not needed here.

Do you really need the ugly "combined" varaible when you have the description???

View solution in original post

8 REPLIES 8
Astounding
PROC Star

So where do you need help?

 

Are you able to create a format from the lookup table (or is that causing trouble)?

 

If you had a format, would  you be able to create the combined column of descriptions (or is that causing trouble)?

sasuser101
Obsidian | Level 7

Thanks for your reply. i need help with

1) Create format using table

2) Apply format toCombined Codes column, so it looks like Combined description

Reeza
Super User

I posted a link in your previous post and @ballardw solution in that post is exactly what I recommend as well and the most efficient. 

 

 

ballardw
Super User

Please examine:

data cntlin;
   set codes;
   start=code;
   end=code;
   label=description;
   Fmtname= 'abc';
   type='C';
;
run;

proc format library=work cntlin=cntlin;
run;

data want;
   set have;
   array v abc_check bgcbs_check jfhfg_check  shdg_check  mi_check ni_check ;
   length combineddescription $ 200;
   do i=1 to dim(v);
      combineddescription = catx(':',combineddescription,put(v[i],$abc.));
   end;
run;

The CNTLIN data set used by Proc format will require several variables and the names must be: Fmtname, start, end, label and type.

 

Fmtname is the name of the format you want to use, start is the beginning value for a range, end is the end value for a range with a single valid then set both the value, label is the text to display and type is designate the format type C=Character or N=Numeric.

there are other options but not needed here.

Do you really need the ugly "combined" varaible when you have the description???

sasuser101
Obsidian | Level 7

Thanks your reply. Can i use your solution to just apply format to Combined Code column? in other words can i replace code with description in Combined Code column by applying format?

ballardw
Super User

IF you create that other variable then the method is in the other question you posted.

 

If you actually need that other variable then add a combinedcode variable to the length statment and create it the same way as the combined description.

There really is absolutely no advantage to creating your combined code variable first and then playing games with pulling a varaible apart to replace things.

novinosrin
Tourmaline | Level 20

I trust you have written a nice code to get the combined codes using array and are only looking for combined description. If your datasets are exactly like the sample, here is one easy solution:

 

 

data want;

if _n_=1 then do;

if 0 then set have;

   declare hash h(dataset:'your_lookup_table');

   h.definekey('code');

   h.definedata('description');

   h.definedone();

   end;

   set your_combined_codes_table;

   length combined_description $50;

   array ch(*)abc_check--ni_check;

   do _n_=1 to dim(ch);

   if not missing(ch(_n_)) then do;

   temp=ch(_n_);

      rc=h.find(key:temp);

   combined_description=catx(':',combined_description,description);

   end;

   else continue;

   end;

   drop temp;

run;

 

I am too lazy and tired to test at 12:05AM past midnight in Chennai. I hope that works for you.

 

Regards,

Naveen Srinivasan

 

sasuser101
Obsidian | Level 7

Thank you for your reply i will try this method as well.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 1219 views
  • 0 likes
  • 5 in conversation