Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Estimating parameters for each group separately (multiple group data)

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 05-28-2021 07:56 PM
(556 views)

Hi,

I need to estimate parameters a and b as well as R-squared from data for each group (expno=1, expno=2, expno=3 etc.,) separately at once. Could someone help me to modify the below codes? Many thanks

```
FILENAME CSV "/folders/myfolders/umar2021.csv" TERMSTR=CRLF;
PROC IMPORT DATAFILE=CSV
OUT=umar
DBMS=CSV
REPLACE;
RUN;
title 'LWR for shells';
data exp;
set umar;
if expno=1 or expno=2 or expno=3;
run;
proc nlin data=exp method=marquardt;
parms B=3 A=0.01;
model w=A*tl**B;
output out=expp p=pw r=w_residual;
run;
proc summary data=expp;
var w_residual w;
output out=stats css(w)=sstot uss(w_residual)=ssres N=N;
run;
data expp;
set stats;
rsquared=1-(ssres/sstot);
adjrsquared = 1-(1-rsquared)*(N-1) / (N- 3 -1);
run;
proc print data=expp;
run;
```

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks, I got the desired results using these codes. Also, the error related to import was also corrected following your suggestions. I attached the SAS output results.

PS. I also need to get plot (figures with curve line using power function) for expno 1, expno 2 and expno 3 where "tl" at x-axis and "w" at y-axis.

9 REPLIES 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Sort your data by expno and use a **BY expno** statement in proc nlin and in proc summary.

PG

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

I modify my codes like as below but I did not get results separately for each group.

```
data exp;
set rapana;
by expno;
if expno=1 or expno=2 or expno=3;
run;
```

Also added in summary like this:

```
proc summary data=expp by expno;
var w_residual w;
output out=stats css(w)=sstot uss(w_residual)=ssres N=N;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello,

If you get errors in the LOG it is better to post the LOG and not just the code.

Your data step will fail if the data are not previously sorted by "expno". Use PROC SORT.

And the BY statement in PROC SUMMARY should be a separate statement, thus preceded by a semicolon.

And your PROC NLIN should have the BY-statement as well.

I repeat what PROC NLIN says about its BY statement. It says much more than the below. The below is just the 1st paragraph. Specify "BY expno;".

The NLIN Procedure

BY Statement

BY variables;

You can specify a BY statement with PROC NLIN to obtain separate analyses of observations in groups that are defined by the BY variables. When a BY statement appears, the procedure expects the input data set to be sorted in order of the BY variables. If you specify more than one BY statement, only the last one specified is used.

Cheers,

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for the comments and hints. I followed them like this:

```
FILENAME CSV "/folders/myfolders/rapana2021.csv" TERMSTR=CRLF;
PROC IMPORT DATAFILE=CSV
OUT=rapana
DBMS=CSV
REPLACE;
RUN;
PROC SORT DATA=exp;
BY expno;
RUN;
```

But got this error:

ERROR: Import unsuccessful. See SAS Log for details.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE IMPORT used (Total process time):

real time 0.54 seconds

cpu time 0.48 seconds

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I need to estimate parameters a and b for each "expno group" (expno 1, 2 and 3 separately).

- Tags:
- @sbxkoenk

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello @afgdurrani0 ,

I see and I understand, but the problem is not in your NLIN-analyses.

You have a PROC IMPORT problem that needs to be solved first.

But why do you import? I see that you have run your analysis on the 3 groups together, so the import has already been done? No need for another PROC IMPORT I would say, correct?

To correct the PROC IMPORT (if still needed), go to the LOG-window and copy the data step that was generated by PROC IMPORT. Paste the data step in your SAS-editor and adjust accordingly until all errors are gone.

You can also import using a UI (User Interface). As well SAS 9.4 as VIYA have UIs to import CSV-files without code.

Cheers,

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks, I got the desired results using these codes. Also, the error related to import was also corrected following your suggestions. I attached the SAS output results.

PS. I also need to get plot (figures with curve line using power function) for expno 1, expno 2 and expno 3 where "tl" at x-axis and "w" at y-axis.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello,

With respect to the plot ...

, this example should give you the right inspiration:

SAS/STAT® 15.2 User's Guide

The NLIN Procedure

Example 87.5 Comparing Nonlinear Trends among Groups

https://go.documentation.sas.com/doc/en/statug/15.2/statug_nlin_examples05.htm

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for the help 🙂

Best regards

Best regards

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.