BookmarkSubscribeRSS Feed
vraj1
Quartz | Level 8

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.

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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.);
vraj1
Quartz | Level 8

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.

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1238 views
  • 0 likes
  • 3 in conversation