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

Below is the code I'm using now to concatenate (up to) 12 pairs of numeric variables, labeled BP_Systolic 1 -12 and BP_Diastolic 1-12.  There is always a pair, no onesies.

length BP_string     $84.;              /* maximum length with "/" is 83.

BP_string = strip(catx('/',put(BP_SYSTOLIC1,best3.),put(BP_DIASTOLIC1,best3.))) || "," ||                                   
strip(catx('/',put(BP_SYSTOLIC2,best3.),put(BP_DIASTOLIC2,best3.))) || "," ||                                                                   strip(catx('/',put(BP_SYSTOLIC3,best4.),put(BP_DIASTOLIC3,best3.))) || "," ||                                                             
strip(catx('/',put(BP_SYSTOLIC4,best3.),put(BP_DIASTOLIC4,best3.))) || "," ||                                                         

 

...This goes on for twelve total sets.                                                                                                                                  

 

What I'd like to do is this:   

 BP_string = catx("/", of _numeric_);      

which is superior then the method above:

Way shorter.                                                                                                                                                                  

If there only one pair of readings, the result is 120/80,                                                                                                 

not 120/80,,,,,,,,, - additional "," for all the missing sets of pairs as in the previous method.                                                

Using   BP_string = catx("/", of _numeric_);   

results in six pairs of reading as:   120/80/115/75/135/82/140/85/130/84/125/81.   That is very good, except I need to replace every 2nd/4th/6th/8th,10th occurrence of  "/" with a comma, as below:

 120/80,115/75,135/82,140/85,130/84,125/81.                                                                                                                 Experimenting with some way to use  BP_string = catx("/", of _numeric_); to concatenate Systolic1, "/", with it's counterpart  Diastolic1, and then Systolic2, "/", with Diastolic2, and so on, until (up to) 12 pairs are read, and then combine them all together separated by a "," - but the below didn't work:  

 BP_string = catx("/", BP_SYSTOLIC1-12, BP_DIASTOLIC1-12); 

 

It is important if there aren't 12 pairs of readings (or any number more than one pair, but less than 12),  there should not be any additional characters.                                                                                                                          

I do have a variable that stores the number of pairs (readings) for each record in the data set .  The average is less then one pair (26% of all observations), but 8 % of the records have the full 12.  Pretty certain the answer resides in an array of some kind. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jumboshrimps
Obsidian | Level 7

Excellent!!!

The function is combining the two numeric readings one at a time, but errors out when the two numerics are

combined with a "/".  Data set returned a blank bp_string column for all records, and an additional column labeled "i" with the number 13 for every record.  Here is my attempt to concatenate the numerics with  put statements:                                                BP_string = catx(",", BP_string, put(catx("/", sys{i}, dia{i}),best3.)));

 

Log reads,

  "NOTE 484-185: Format $BEST was not found or could not be loaded."

 

I know best3. works as I used it in the old way as:

strip(catx('/',put(BP_SYSTOLIC1,best3.),put(BP_DIASTOLIC1,best3.))) || "," ||

which produced the correct result, but not really pushing the envelope in terms of SAS.

Using format comma10.0 also gave the same error.

 

 

 


NOTE: Invalid numeric data, '119/59' , at line 33 column 14.
NOTE: Invalid numeric data, '131/74' , at line 33 column 14.
NOTE: Invalid numeric data, '122/66' , at line 33 column 14.
NOTE: Invalid numeric data, '126/74' , at line 33 column 14.
NOTE: Invalid numeric data, '142/80' , at line 33 column 14.
NOTE: Invalid numeric data, '104/70' , at line 33 column 14.
NOTE: Invalid numeric data, '120/70' , at line 33 column 14.
NOTE: Invalid numeric data, '125/71' , at line 33 column 14.
NOTE: Invalid numeric data, '126/72' , at line 33 column 14.
NOTE: Invalid numeric data, '116/69' , at line 33 column 14.

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

This would be simpler:

 

option missing=" ";
array sys BP_SYSTOLIC1-BP_SYSTOLIC12;
array dia BP_DIASTOLIC1-BP_DIASTOLIC12;
do i = 1 to dim(sys);
	BP_string = catx(",", BP_string, catx("/", sys{i}, dia{i}));
	end;
run;

(untested)

PG
Jumboshrimps
Obsidian | Level 7

Excellent!!!

The function is combining the two numeric readings one at a time, but errors out when the two numerics are

combined with a "/".  Data set returned a blank bp_string column for all records, and an additional column labeled "i" with the number 13 for every record.  Here is my attempt to concatenate the numerics with  put statements:                                                BP_string = catx(",", BP_string, put(catx("/", sys{i}, dia{i}),best3.)));

 

Log reads,

  "NOTE 484-185: Format $BEST was not found or could not be loaded."

 

I know best3. works as I used it in the old way as:

strip(catx('/',put(BP_SYSTOLIC1,best3.),put(BP_DIASTOLIC1,best3.))) || "," ||

which produced the correct result, but not really pushing the envelope in terms of SAS.

Using format comma10.0 also gave the same error.

 

 

 


NOTE: Invalid numeric data, '119/59' , at line 33 column 14.
NOTE: Invalid numeric data, '131/74' , at line 33 column 14.
NOTE: Invalid numeric data, '122/66' , at line 33 column 14.
NOTE: Invalid numeric data, '126/74' , at line 33 column 14.
NOTE: Invalid numeric data, '142/80' , at line 33 column 14.
NOTE: Invalid numeric data, '104/70' , at line 33 column 14.
NOTE: Invalid numeric data, '120/70' , at line 33 column 14.
NOTE: Invalid numeric data, '125/71' , at line 33 column 14.
NOTE: Invalid numeric data, '126/72' , at line 33 column 14.
NOTE: Invalid numeric data, '116/69' , at line 33 column 14.

Jumboshrimps
Obsidian | Level 7
This works:


BP_string = catx(",", BP_string, put(catx("/", sys{i}, dia{i}),3.));

There is a God.

Thank everyone!!!!
best3. was some kind of custom format somewhere in this 10,000 lines of goo I inherited.
PaigeMiller
Diamond | Level 26

And once you have these long strings created properly, then what are you going to do with them? How would you use them?

 

It seems to me that creating this data structure, with numbers as a part of a long string, is horribly inefficient and destroys any further simplicity of programming.


So, you might be wise to consider more useful data structures, which could require much simpler programming. What that might be, I don't know, because I don't know what you are planning to do next.

--
Paige Miller

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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