Help using Base SAS procedures

Attempting to merge data sets but PAT_MAR is character in the melig dataset

Reply
N/A
Posts: 0

Attempting to merge data sets but PAT_MAR is character in the melig dataset

Hi,

I would like to merge two datasets called report.FY08_datanodup and report.melig. The problem is that they are not in the same format. I attempted to correct the melig file for PAT_MAR to be numeric instead of character. it isn't working, please help. Thanks.

data one;
set report.melig;
newmar = 1*PAT_MAR;
run;
proc sort data = report.FY08_datanodup;
by PAT_ID;
run;



proc sort data = report.melig;
by PAT_ID;
run;
Contributor
Posts: 29

Re: Attempting to merge data sets but PAT_MAR is character in the melig dataset

Posted in reply to deleted_user
Convert to a numeric with the input fuction:

newmar = input(PAT_MAR,10.);

or

You can also convert to a character with the put function:

x = put(num_var, $10.);
Super Contributor
Posts: 359

Re: Attempting to merge data sets but PAT_MAR is character in the melig dataset

Posted in reply to deleted_user
Why are you sorting report.melig after you create one with the new numeric variable?
N/A
Posts: 0

Re: Attempting to merge data sets but PAT_MAR is character in the melig dataset

Posted in reply to deleted_user
Thanks for your help. I am attempting to merge two files report.Fiscal08_datanodup and report.melig, but the variable PAT_MAR is numeric in one and character in the latter file.

Anyway I attempted to do the following, but the log said

data report.six;
48 merge one report.melig;
ERROR: Variable PAT_MAR has been defined as both character and numeric.
49 by PAT_ID;
50 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set REPORT.SIX may be incomplete. When this step was stopped there were 0
observations and 91 variables.
WARNING: Data set REPORT.SIX was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.00 seconds


Rabiya

Please help.

data one;
set report.Fiscal08_datanodup;
x = put(num_var, $10.);
run;
proc sort data = one;
by PAT_ID;
run;


proc sort data = report.melig;
by PAT_ID;
run;
data report.six;
merge one report.melig;
by PAT_ID;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Attempting to merge data sets but PAT_MAR is character in the melig dataset

Posted in reply to deleted_user
Your SAS variables listed in the BY statement must be of a consistent type, either NUMERIC or CHARACTER, and each of your input file specified on the MERGE statement must be sorted in the same sequence as listed in the BY list (in a typical scenario). Since you cannot have one variable with two different types, you are faced with doing a variable DROP and a RENAME process, so that you get back to having your BY variables all having the appropriate name.

So, one technical is to do the RENAME= on the SET for the file you want to modify, and then assign the same-named BY variable with the necessary ATTRIB (or LENGTH) attributes and derivation code, such as the INPUT function. After performing you data manipulation, verify the SAS variable results in each of your to-be-merged files using SAS PROC CONTENTS.

Once you have confirmed the SAS variable attributes are consistent, then move forward with your DATA step MERGE process.

The SAS support website http://support.sas.com/ hosts SAS product documentation and also additional user community (SGF and SUGI) technical papers as well as SAS-contributed technotes.

For example, I did a Google advanced search against the SAS.COM site - here is the argument entered:

data step merge processing site:sas.com


A SEARCH facility is also provided at the SAS support website, in addition to the Google example.

Here is a tech doc paper found from a search:

http://support.sas.com/techsup/technote/ts644.pdf

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 4 replies
  • 105 views
  • 0 likes
  • 4 in conversation