Help using Base SAS procedures

proc print : create and apply a format based on dataset

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 117
Accepted Solution

proc print : create and apply a format based on dataset

Hello,

 

I have 3 key figures and I would like to print with a specifiq format.

each figure has an old label (measure_label_from)  and a new label (measure_label_to).

what I try to do is to translate the label of the figure by using a format.

It works for 2nd and the 3rd figure but NOT for the first. I don't know why.

thanks in adance for your help

Nasser

 
Data T_indicateurs ;
infile datalines dsd;
input figures ~ $50. amount ;
datalines ;
'Mont DDT sans cumul M0'   , 9999
'Mont LRA sans cumul M0'   , 1234
'Taux DDT ECR sans cumul M0'  , 0.65
run ;

Data T_indicateurs ;
Set T_indicateurs ;
figures = compress(figures,"'") ;
Run ;


Data T_indic_transco ;
infile datalines dsd;
input measure_label_from ~ $50. measure_label_to ~ $50. ;
datalines ;
'Mont DDT sans cumul M0'   , 'ENTREE MENS DDT&SU'
'Mont LRA sans cumul M0'   , 'ENTREE MENS EN RA'
'Taux DDT ECR sans cumul M0'  , 'TX DE SORTIE DDT&SU / Encours'
run ;

Data T_indic_transco_format (Drop = measure_label_from measure_label_to) ; 
Set T_indic_transco ;
Retain FMTNAME '$f_measure_label' ;
START = Compress(measure_label_from,"'") ;
LABEL = Compress(measure_label_to,"'") ; 
Run ;

Proc format CNTLIN =  T_indic_transco_format ; run;

proc print data=T_indicateurs ; 
format figures $f_measure_label. ;
run ;

please, run this code and you will notice that only the first row is not translated

 

 


Accepted Solutions
Solution
‎11-06-2017 09:10 AM
Super User
Posts: 10,279

Re: proc print : create and apply a format based on dataset

Posted in reply to Nasser_alfea

Just to make sure: copy/paste the code from your original post back into SAS and run it.

 

What encoding are you using for your SAS session?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 10,279

Re: proc print : create and apply a format based on dataset

Posted in reply to Nasser_alfea

Running your code gives me this result:

Beob.    figures                           amount

  1      ENTREE MENS DDT&SU               9999.00
  2      ENTREE MENS EN RA                1234.00
  3      TX DE SORTIE DDT&SU / Encours       0.65

Looks fine to me, all "figures" values were re-formatted.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 117

Re: proc print : create and apply a format based on dataset

Posted in reply to KurtBremser

Thanks Kurt. for me It doesn't work. running the code gives me this result.

Capture.PNG

Solution
‎11-06-2017 09:10 AM
Super User
Posts: 10,279

Re: proc print : create and apply a format based on dataset

Posted in reply to Nasser_alfea

Just to make sure: copy/paste the code from your original post back into SAS and run it.

 

What encoding are you using for your SAS session?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 117

Re: proc print : create and apply a format based on dataset

Posted in reply to KurtBremser

I have copy/paste the code from my original post into sas and then it works now.

thanks a  lot Kurt !!! 

Super User
Posts: 10,279

Re: proc print : create and apply a format based on dataset

Posted in reply to Nasser_alfea

Then it's most probable that posting here filtered out an invisible mis-type contained in your code.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 117

Re: proc print : create and apply a format based on dataset

Posted in reply to KurtBremser

Yes Kurt,

  

I noticed that in the step "datalines" I put some tabulation between values and I noticed that it does NOT work for each lines (transco) that hold a TABULATE and it works for all lines without tabulate.

so by replacing all tabulations by just space, every lines work !!!


thanks kurt !

Super User
Posts: 10,279

Re: proc print : create and apply a format based on dataset

Posted in reply to Nasser_alfea

I have my EG enhanced editor set to always replace all tabs (entered or read from file) with spaces. This also does away with problems caused by different tab spacings (ie 2 in EG, but 8 on UNIX).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 188 views
  • 1 like
  • 2 in conversation