BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5

Hi,

I am very puzzled, I've ran the proc freq as art297 kindly suggested and used the the "/" to get an output data for these results, now I have to merge the true freq table with observed freq table. The problem is that when I do merge them only the first data set's full information shows. how can I fix this?

thanks

my code:

proc freq data=c10000.c10000_D1 ;

tables True_Class / out=c10000.D1;

tables Est_Class  / out=c10000.D2;

tables True_class*Est_Class / out=c10000.D3;

Run;

data c10000.D1;

set c10000.D1;

obs=_n_;

run;

data c10000.d22;

set c10000.d2;

    label count=Est_Frq percent=est_perc;

    run;

    data c10000.d11;

set c10000.d1;

    label count=tru_Frq percent=tru_perc;

    run;

data c10000.D22;

set c10000.D2;

obs=_n_;

run;

proc sort data=c10000.D1 out=c10000.D1; by obs;

run;

proc sort data=c10000.D2 out=c10000.D2; by obs;

run;

data c10000.Freqency;

merge c10000.D22 c10000.D11; by obs;

run;

proc print data=c10000.Freqency;

run;

3 REPLIES 3
data_null__
Jade | Level 19

The variables are being overwritten by the data set on the right in MERGE.

These statements need to be RENAME not LABEL

label count=Est_Frq percent=est_perc;

Plus you don't need a complete do nothing data step just to rename use data set options on MERGE statement.

HOWEVER,  I think you could do this more easily with with ODS OUTPUT and ONE table statement for the crossed table. But I can't give you any details because I don't know what you want.

R_A_G_
Calcite | Level 5

Thanks for the comment but RENAME does not work, LABEL does, I do not know why.

also I am attaching the files I am trying to merge.

D11 data file has these variables: True_Class tru_frq tru_perc obs

D22 data file has set_class est_frq est_perc obs

merging into:

FREQUNCY data file but the problem is after merging this data file has only these variables in them:

True_class tru_frq tru_perc obs

I don't know what I am doing wrong

thanks

art297
Opal | Level 21

Like DN, I don't know why you didn't just use ODS.  Regardless, given that you have the same number of records in each file, and in the same order, why not combine them with:

PROC IMPORT OUT= WORK.d11

  DATAFILE= "C:\art\d11.xls" 

            DBMS=xls REPLACE;

  GETNAMES=YES;

  DATAROW=2; 

RUN;

PROC IMPORT OUT= WORK.d22

  DATAFILE= "C:\art\d22.xls" 

            DBMS=xls REPLACE;

  GETNAMES=YES;

  DATAROW=2; 

RUN;

PROC IMPORT OUT= WORK.frequency

  DATAFILE= "C:\art\frequency.xls" 

            DBMS=xls REPLACE;

  GETNAMES=YES;

  DATAROW=2; 

RUN;

data want;

  set frequency (rename=(count=freq_count

                         percent=freq_percent));

 

  set d11 (keep=count percent

                 rename=(count=d11_count

                   percent=d11_percent));

   set d22 (keep=count percent

                 rename=(count=d22_count

                   percent=d22_percent));

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1423 views
  • 0 likes
  • 3 in conversation