BookmarkSubscribeRSS Feed
sreeparna93
Calcite | Level 5

Hi I want to add line while concatenating variables. tried a few things. Dont seem to get it done. 

The code is 

 

		DATA Y;
		SET result;
		INFORMAT R $100.;
		format R $100.;
		R = CATX(":" ,"CDE" , cde_name, "Attribute", attrib_name);
 		where total_record_count gt 10.00 or total_record_count lt -10.00;	
		RUN;
		PROC PRINT;
		title 'Y';
		RUN;


		proc sql;
		select (catx("^{newline 1}",R)) into :var separated by '^{newline 1}' from y 
		where total_record_count gt 10.00 or total_record_count lt -10.00;
		run;
Now I only get CDE:PRODUCT HIERARCHY:Attribute:PRD_HRCHY_LVL_2_CDE^{newline 1}CDE:PRODUCT 
2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, your post is not clear.  Post test data, in the form of a datastep.  Also post what you want out at the end.  Why for instance are you taking data from a datastep and putting it and formatting values into a macro variable?  Its likely your hitting a length issue, but really can't tell what you trying to do at all.  If you want some sort of list then:

data y;
  set result (where=(total_record_count gt 10.00 or total_record_count lt -10.00)) end=last;
  length r final $2000;
  retain final;
  r=catx(":","CDE",cde_name,"Attribute",attrib_name);
  final=ifc(_n_=1,r,catx(":",final,r));
  if last then call symputx('VAR',final);
run;

However that really isn't a good way to do things, you will hit line var lengths and your code will be all spaghetti.

Kurt_Bremser
Super User

Don't keep lists in macro variables. Keep them in datasets. It is much easier to create line-separated output with proc print or a data step.

 

What for would you use such a macro variable, anyway?

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3847 views
  • 0 likes
  • 3 in conversation