DATA Step, Macro, Functions and more

how to merge formats to dataset

Reply
Regular Contributor
Posts: 200

how to merge formats to dataset

I have 2 datasets one with format which has char and numeric values and other main dataset.

 

I waant to make the numeric value to character in main dataset and use the sorting of formatted nueric value in anl2 as sort variable to get the sort. Tried many ways bit could nt figure out. Any help?

 

attached 2 test datasets.

Attachment
Attachment
Super User
Super User
Posts: 9,209

Re: how to merge formats to dataset

First off post test data using a code window - its the {i} above the post area.

Secondly, there doesn't seem to be anything in common between the two data you provided - aval/c is not in main, and none of main is in anl2.

Thirdly, are you creating SDTM or ADaM here?  If it is ADaM then the code value should come in from SDTM as text, then in ADaM you can also have a numeric.  If its SDTM, then yes you would have a text codelist.

Super User
Posts: 9,569

Re: how to merge formats to dataset

[ Edited ]

To create a format from anl2, do this:

data WORK.ANL2;
  infile datalines dsd truncover;
  input AVALC:$200. AVAL:32.;
datalines4;
Adverse event,1
Lack of efficacy,2
Non-compliance with IMP,3
Protocol violation,4
Withdrawal of consent,5
Lost to follow-up,6
Did not fulfill inclusion criteria for Period B,7
Other,8
;;;;
run;

data cntlin;
set anl2 (rename=(aval=start avalc=label));
fmtname = 'aval';
type = 'n';
run;

proc format library=work cntlin=cntlin;
run;

You can now apply that format like

format primreas aval.;

or create a new variable

primreasc = put(primreas,aval.);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Regular Contributor
Posts: 200

Re: how to merge formats to dataset

Posted in reply to KurtBremser

Hi Kurt,

 

In fact i did that but i need the order to be as it is in aval. for that i need to make a sort variable to sort but unfortunately i dont have any common observation to merge.

Super User
Posts: 9,569

Re: how to merge formats to dataset

Applying the format to primreas will not change the order of a proc sort. Procedures that can order by formatted values usually have options to suppress this.

Or you create a new variable and leave primreas itself untouched.

No merge is needed to apply a format.

If you still have problems, supply an example for the expected result, based on your example data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 4 replies
  • 114 views
  • 0 likes
  • 3 in conversation