proc format separted by semi colon

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

proc format separted by semi colon

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


Accepted Solutions
Solution
‎04-25-2017 08:08 PM
Super User
Posts: 11,343

Re: proc format separted by semi colon

Posted in reply to sasuser101

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


All Replies
Super User
Posts: 5,498

Re: proc format separted by semi colon

Posted in reply to sasuser101

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)?

Contributor
Posts: 29

Re: proc format separted by semi colon

Posted in reply to Astounding

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

Super User
Posts: 19,771

Re: proc format separted by semi colon

Posted in reply to sasuser101

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. 

 

 

Solution
‎04-25-2017 08:08 PM
Super User
Posts: 11,343

Re: proc format separted by semi colon

Posted in reply to sasuser101

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???

Contributor
Posts: 29

Re: proc format separted by semi colon

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?

Super User
Posts: 11,343

Re: proc format separted by semi colon

Posted in reply to sasuser101

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.

PROC Star
Posts: 283

Re: proc format separted by semi colon

[ Edited ]
Posted in reply to sasuser101

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

 

Contributor
Posts: 29

Re: proc format separted by semi colon

Posted in reply to novinosrin

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 154 views
  • 0 likes
  • 5 in conversation