Help using Base SAS procedures

Need some info in PROC format

Reply
N/A
Posts: 0

Need some info in PROC format

Hi,

I need some info on the limit of length of character Variable used in PROC FORMAT Value statement. I have some data related to Health Risk Appraisal, where questions are very long (to 200 bytes max). I need to map these questions to a question code for each question in PROC FORMAT. Please let me know if any other way to do this other than in if statement in data step statement.

thanks,
Super Contributor
Super Contributor
Posts: 3,174

Re: Need some info in PROC format

Explore using PROC FORMAT with CNTLIN= to create your SAS format from a SAS input file. The DOC has all the information you need.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search arguments, this topic/post:

proc format cntlin site:sas.com

proc format character format site:sas.com
N/A
Posts: 0

Re: Need some info in PROC format

hi Support,

I have checked the documentation, but I am not sure how to refer the lookup value referred to the question in proc format.

I read in all possible questions that I will be getting in the data and assigned a question code for each of the question (which was 250 byte long). I used PROC Format on dataset which had variables.

My code is like this -

data lookup ;
infile inp lrecl = 300 recfm = v delimiter = ',' end = eof dsd truncover ;

length questnin $250.
quesncd $7.
questxtcd $258.
;


input

questnin $
quesncd $
;

questxtcd = Trim(quesncd) || '-' || Trim(questnin) ;

start = questxtcd ;
LABEL = 'KEEP' ;
FMTNAME = '$queskey';

run;

PROC SORT DATA = lookup OUT = FMTOUT NODUPKEY ;
BY start ;

PROC FORMAT CNTLIN=FMTOUT;
run;


So when I read in my raw file - when I refer to CNTLIN format on the raw variable for question we are getting, I am not getting desired output.

Say for example I have a question like this - "HOW MANY HOURS OF SLEEP DO YOU USUALLY GET AT NIGHT?" where I gave QUEST1

So when ever I encounter this question on data, I need to output Quest1 instead of that so long full question. Looks like my reference to PROC Fromat is not working -

HA_QUES_TXT = put(Trim(Left(HA_QUESTION_TEXT)),$QUESKEY.);

HA_QUESTION_TEXT is variable in raw data that I am getting.

Please let me know what else I need to take care to output value "QUEST1".

thanks in Advance,
LG
Super Contributor
Super Contributor
Posts: 3,174

Re: Need some info in PROC format

For clarification, this is not SAS Technical Support - that's a different (paid) channel, except maybe the wonderful and thought-provoking Cynthia...

Your SAS code that builds the START variable must match exactly the SAS code that constructs the PUT function argument #1.....they do not appear to be consistent.

So, for self-debugging, have you attempted to analyze the generated format, either with the PROC FORMAT FMTLIB parameter, or better yet, use CNTLOUT= to unload your format and do a PROC PRINT on the SAS-generated file specified on CNTLOUT.

You mention something about "..I need to output Quest1..." but you do not share allof your SAS DATA step code that uses HA_QUES_TXT -- the variable assigned from the PUT function. A match-condition will result in a value of KEEP -- so what do you do then?

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Need some info in PROC format

Hi Sbb,

Thanks for response. It gave me some direction on how to approach, but not exactly what I needed.

I thought Arg #1 after lookup to PROC FORMAT will result in the short form of Question. But that's not happening. not sure how to get this resolved.

Any ideas would help me a lot and I appreciate it.

thanks,
LG
Super Contributor
Super Contributor
Posts: 3,174

Re: Need some info in PROC format

Possibly, if you want SAS to return the short-form (your words) on a "match condition", then you need to assign whatever you expect back with the LABEL variable, not the string "KEEP" which only identifies when you have a "match condition" but provides no relief to save some data back from the format.

Also, with creating your CNTLIN= file, after you output the last observation (on END=EOF with the SET stmt), then you want one additional observation for the OTHER= telling SAS what to return on a no-match condition. The DOC explains this technical application / approach.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 5 replies
  • 127 views
  • 0 likes
  • 2 in conversation