View previous topic :: View next topic
|
Author |
Message |
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
Hi,
I am trying to build SAS Title based on Input fields from a Control Card.
There will be 5 fields in control card. But my title is bsed on 2 fields from those 5. Fields can be default or some value in it. Default wil be 9's
fields
ID - 3 byte
Loc - 3 byte
gender - 2 byte
emp-type - 2 byte
Salary - 6 byte
I can have combinations of fields and depending on which i am trying to generate a report. ANd this report needs to have a title based on ID and EMp-type.
If ID = 999 and EMP-TYPE = 99 IT MEANS REPORT IS NOT BASED ON THESE FIELDS
IF id = ABC AND EMP-TYPE = 99 IT MEANS REPORT IS BASED ON ID
IF ID = ABC AND EMP-TYPE = 01 THEN IT MEANS REPORT IS BASED ON BOTH
IF ID = 999 AND EMP-TYPE = 01 THEN IT MEANS REPORT IS BASED ON EMP-TYPE ONYL.
NOW MY REQUIREMENT IS TO SHOW THE CRITERIA ON WHICH MY REPORT GOT GENERATED.
FOR EXAMPLE
ID - 999
TYPE - 01
TITLE NEEDS TO BE - TITLE "CRITERIA: TYPE - 01"
EX2:
ID - ABC
TYPE - 01
TITLE "CRITERIA: ID - ABC TYPE - 01"
EX3
ID - ABC
TYPE - 99
TITLE "CRITERIA: ID - ABC"
EX4
ID - 999
TYPE - 99
NO TITLE
======
i am trying to do this in a SAS program, as a macro.
I would need code for the same.
Input - Control Card Example -
Control card can have max of 5 rows. with each row having 16 bytes each and no criteria on a fields will be represented by 9's.
default value for a field will be 9's.
ex:
Fields in a row - ID/loc/gender/emp-type/salary wil be without any space inbetween.
ABCOHIFEPE500000
EX2:
999FLOMA99126700
Ex3:
BCDPENFE99670000
EX4:
999BOSMATE230000
Reading this input say if they are in a control card as 4 rows.
Then my title needs to be like
TITLE "CRITERIA: ID - ABC TYPE - PE"
TITLE "CRITERIA: ID - BCD"
TITLE "CRITERIA: TYPE - TE"
Thanks
-Kranthi |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hi,
If there are subsequent title statements on after the other, then I guess you are aware that the last title statement would override the previous title statements and only the last title statement would be in effect.
So If you have 4 control cards and somehow generate 4 title statements, then only the 4th title statement would be in effect.
on the other hand,
The 4 titles will be simultaneously in effect only if you have statements like,
TITLE1 "something"
TITLE2 "something else"
TITLE3 "some other thing"
TITLE4 "some some other thing"
Are you sure that you require title statements subsequently? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Does SAS allow datanames in title statements? If so, get on with the code.
If not, find the "highest level" element in a SAS report description which can have a dataname, and use that. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Easily enough done using a macro. Have done it myself many a time. |
|
Back to top |
|
|
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
@Vasanth,
It is not 4 control cards...
It is 4 records in a control card.
Yes I would need 4 Titles if I have 4 records in control card.
I wanted to do it using MACRO. But not sure of what/how it can be done.
@ Others,
Please post the MACRO coding.
Thanks to every one for the replies. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
You need to analyse your input data to determine the contents of the title pages, and then build a macro variable to contain that information.
Then use
Code: |
Title1 = &variable. |
Kranthi wrote: |
M@ Others,
Please post the MACRO coding. |
My daily rate for such activites is 750 euro. Code delivered upon receipt of payment |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
Back to top |
|
|
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
Hi,
Every time I read a record from Control card, I want to call a macro that will build title based on input. How Can i do it?
In that case do i need to have the DATA part of control card within the MACRO or outside macro. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
What happens when you try various options? |
|
Back to top |
|
|
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
for each record in the control card I need a title. And title needs to have variables from control card. |
|
Back to top |
|
|
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
Can some one tell what is wrong with below code:
It says MACRO is not invoked. Warning - Apparent invocation of macro CRITERIA not resolved.
and an error
ERROR: Expected %TO not found in %DO statement. A dummy macro will be compiled.
=====
DATA FILEA;
INFILE CARDIN;
INPUT @01 ID $03.
@04 LOC $03.
@07 GENDER $02.
@09 EMPTYPE $02.
@11 SALARY $06.
@17 FILL1 $64.;
TEMPVAR = 'ANY VALUE'; /* THIS NEEDED TO GET SYMPUT TO WORK */
CALL SYMPUT('ID1',ID);
CALL SYMPUT('EMPTYP',EMPTYPE);
%CRITERIA(IDEN=&ID1,EMPT=&EMPTYP);
%MACRO CRITERIA;
%IF &IDEN = 999
%THEN %DO
SELECT = 1;
TITLE1 "CRITERIA SYMBOL &SYM AND STATE &RST";
%IF &EMPT = 99
%THEN %DO SELECT = 2;
TITLE1 "ALL SYMBOLS AND ALL STATES";
%END;
%ELSE
%DO SELECT = 3;
TITLE1 "CRITERIA SYMBOL &SYM";
%END;
%ELSE
%DO SELECT = 4;
TITLE1 "CRITERIA RISK STATE &RST";
%END;
%MEND CRITERIA; |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Have you tried to define the macro before you try to invoke it |
|
Back to top |
|
|
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
Yes, i have it a library and I used some option to tell SAS that macro is in certain library.
Now invocation is not problem.
%LOSO720D(IDEN=&id1,EMPT=&EMPTYP);
an error at above line - says
Statement is not valid or it is used out of proper order.
And the DO seems to have some problem in the MACRO. it gives an error
Expected %TO not found in %DO statement. |
|
Back to top |
|
|
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
Just happened to resolve 1 issue with
%CRITERIA(IDEN=&ID1,EMPT=&EMPTYP);
As ID and EMPTYPE are global, i dont need to pass them while invoking. just use them with & within MACRO.
Looking into other issue.
Thanks |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
One more obvious error is, the macro criteria has 4 %DOs and 3 %ENDs.
1 more is needed. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Also All the %DO statements in your program
has to have an accompanying %TO statement or has to end with a semicolon.
like %DO; |
|
Back to top |
|
|
Kranthi M
New User
Joined: 07 Oct 2011 Posts: 20 Location: India
|
|
|
|
Thanks Vasanth. I resolved the DO loop thing. But this way I was only printing one title as you said. It was overriding all others.
So for printing all the titles i might need to use ARRAY and then use
Instead of TITLE, I am just displaying all the records in the control card with a title saying CRITERIA using PROC PRINT. And another PROC PRINT to print the actual REPORT. This way I can display the CRITERIA in a easy way.
I know this is not what I intended for initially but can not afford to put more efforts by building macro and use ARRAYs as well to build 10 titles dynamically.
Thanks every one! |
|
Back to top |
|
|
|