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

Windows 10, SAS Version 9.4

I would like to add 2 observations to a dataset.  To do so, I wrote the following code within a macro prior to sort and merge by variable named "compound2" of type char $3.

data work.addcompounds2GFC;
		input compound2=$3. GFC_Suc_MPB= Final_Weigh_SD=;
		datalines;
 			compound2=Cl GFC_Suc_MPB=0 Final_Weigh_SD=0
			compound2=S  GFC_Suc_MPB=0 Final_Weigh_SD=0
			; 

proc print data=work.addcompounds2GFC; run;

 When I compile just the code as shown above, the result is just the desired dataset (work.addcompounds2GFC).

1.JPG          

I was also able to do this using cards:

 

data work.addcompounds2GFC;
				length compound2 $3;
				input compound2 $ GFC_Suc_MPB Final_Weigh_SD;
				cards;
					Cl 0 0
					S 0 0
			; 
			run;

This code is nested within a macro.  While compilation works in pieces, running the macro as a whole leads to the following error message:

ERROR: The macro RUN4_CALCULATIONS generated CARDS (data lines) for the DATA step, which could
       cause incorrect results.  The DATA step and the macro will stop executing.

What I want, and this works if I just run a portion of code within the macro, is to combine this data with another dataset with the new observations for Cl and S:

 

2.JPG   

Thank you, Jane

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Reeza
Super User
You cannot use cards or data lines within a macro. However you can use SQL INSERT instead.

https://documentation.sas.com/?docsetId=sqlproc&docsetTarget=n1ncn0pznd8wrln1tnp3xdxjz9xz.htm&docset...
jawhitmire
Quartz | Level 8

Thank you for the quick reply.

 

The information at the link was informative and the following correction fixed the problem.

 

proc sql;
				create table work.addcompounds2GFC(compound2 char(3), GFC_Suc_MPB num, Final_Weigh_SD num);
				insert into work.addcompounds2GFC
					values('S',0,0)
					values('Cl',0,0);

Thanks again. Cheers!

 

Jane

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 593 views
  • 3 likes
  • 2 in conversation