DATA Step, Macro, Functions and more

Change value in a dataset

Reply
New Contributor
Posts: 2

Change value in a dataset

Hi,

 

How can I write this as a datastep to change the actual values stored in the variable 'LBTEST' in 9.4?

 

If I use the below Proc format and then Proc Print the updated values show, but how can I save the updated dataset?

 

proc format;
value $LBTEST

        'Albumin (Alb)'='Albumin'
       'Alanine aminotransferase (ALT)'='Alanine aminotransferase'
       'Alkaline phosphatase (ALP)'='Alkaline phosphatase'
      'Aspartate aminotransferase (AST)'='Aspartate aminotransferase'
   'Basophils - % (Baso %)'='Basophils (%)'
  'Basophils - Absolute (Baso Abs)'='Basophils (Abs)'
 'Blood urea nitrogen (BUN)'='Blood urea nitrogen'
run;

 

proc print data=ABNLABKEEP;
format LBTEST $LBTEST.;
run;

PROC Star
Posts: 172

Re: Change value in a dataset

[ Edited ]

Do you mean ?:

data ABNLABKEEP;

set ABNLABKEEP;

format LBTEST $LBTEST.;
run;

 

Super User
Posts: 5,096

Re: Change value in a dataset

To actually change the values:

 

data WANT;

set ABNLABKEEP;

LBTEST = put(LBTEST, $LBTEST.);
run;

New Contributor
Posts: 2

Re: Change value in a dataset

Thanks!

 

I get an error.... SnipImage.JPG

PROC Star
Posts: 7,364

Re: Change value in a dataset

I have to guess that you made some kind of mistake in creating the format. The following works for me:

data ABNLABKEEP;
  informat lbtest $80.;
  input lbtest &;
  cards;
Albumin (Alb)
Alanine aminotransferase (ALT)
Alkaline phosphatase (ALP)
Aspartate aminotransferase (AST)
Basophils - % (Baso %)
Basophils - Absolute (Baso Abs)
Blood urea nitrogen (BUN)
;

proc format;
value $LBTEST
        'Albumin (Alb)'='Albumin'
       'Alanine aminotransferase (ALT)'='Alanine aminotransferase'
       'Alkaline phosphatase (ALP)'='Alkaline phosphatase'
      'Aspartate aminotransferase (AST)'='Aspartate aminotransferase'
   'Basophils - % (Baso %)'='Basophils (%)'
  'Basophils - Absolute (Baso Abs)'='Basophils (Abs)'
 'Blood urea nitrogen (BUN)'='Blood urea nitrogen'
run;

data WANT;
set ABNLABKEEP;
LBTEST = put(LBTEST, $LBTEST.);
run;

Art, CEO, AnalystFinder.com

 

Super User
Posts: 10,543

Re: Change value in a dataset

Or perhaps make that format an INVALUE and use it as an INFORMAT to read the data. This may be a better option in the long run if you are reading multiple files with the same contents.

Ask a Question
Discussion stats
  • 5 replies
  • 106 views
  • 0 likes
  • 5 in conversation