BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
laiguanyu001
Fluorite | Level 6

Hi, 

I want to create a dataset that looks like this

 

data out;

input id description $ num_of_errors error $;

datalines;

1001 some_string &count_of_record some_error

;

data table1;

input test;

datalines;

1

2

3

;

 

here I want &count_of_record to be the number of rows from table1. so when I print the data out,

the result will look like this

 

id          description               num_of_error         error

1001        some_string                 3                    some_error

 

I'm wondering if there's a programming way to do this instead of manually type in. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

No macro needed. Basic manipulation of data rarely requires macros.

 

proc summary data=table1;
    var test;
    output out=ntable n=num_of_errors;
run;

data out;
    if _n_=1 then set ntable(drop=_:);
    input id description $ error $;
    datalines;
...
;
run;

Also, you can't have macro variables inside DATALINES 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

No macro needed. Basic manipulation of data rarely requires macros.

 

proc summary data=table1;
    var test;
    output out=ntable n=num_of_errors;
run;

data out;
    if _n_=1 then set ntable(drop=_:);
    input id description $ error $;
    datalines;
...
;
run;

Also, you can't have macro variables inside DATALINES 

--
Paige Miller
laiguanyu001
Fluorite | Level 6

thanks!! But what if my table1 also has some character values? I don't think proc summary works in that case. 

PaigeMiller
Diamond | Level 26

@laiguanyu001 wrote:

But what if my table1 also has some character values?


Llittle known fact, if you omit the VAR command, PROC SUMMARY will count the number of observations, even if there are only character variables.

proc summary data=have;
	output out=_stats_ ;
run;

 

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1029 views
  • 1 like
  • 2 in conversation