DATA Step, Macro, Functions and more

how to concatenate the values with two macro values as variable names in data set

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

how to concatenate the values with two macro values as variable names in data set

Hello guys,

 

I have a table like the below,

var1       var2    var3   var4     var5

npass     23      34        27        43

nfail        20      18        37        16

npper      23/43 34/52   27/64  43/59

nfper      20/43   18/52  37/64   16/59

 

what I want is :

var1           var2                    var3                    var4                   var5

npass       23 (53.4%)          34 (65.4%)          27 (42.2%)        43 (72.9%)

nfail          20(46.6%)           18 (34.6%)          37 (57.8%)        16 (27.1%)

 

npper is passing percent , nfper is failing percent. the Var2   var3 var4 var5' s names are macro values. those macro values changes month by month.

 

Thanks a lot!

  

 

 


Accepted Solutions
Solution
a week ago
Respected Advisor
Posts: 2,649

Re: how to concatenate the values with two macro values as variable names in data set


@daisy6 wrote:

I want a table as data set. The percents and pass number in the exact same cell  of the dataset. 


The idea of having a cell in a SAS data set that contains the text "23 (53.4%)" seems utterly useless to me. What possible use of such a data set could there be?

 

However, if you really want to do this, you create a data set where the calculations are done and there are numbers in each cell, 23 in one cell, 53.4 in another cell (PROC SUMMARY could do this easily), and then using a data step, convert these values to characters and concatenate them. I do not have the time today to advise further on the exact code. Please see if you can make this work based upon the description I have given.

 

 

--
Paige Miller

View solution in original post


All Replies
Respected Advisor
Posts: 2,649

Re: how to concatenate the values with two macro values as variable names in data set

Do you want a table (for example from PROC REPORT) as output, or data set as output?

 

In either case, do you want the percents in the exact same cell of the table/data set, or are the percents in a different column?

 

 

 

--
Paige Miller
Frequent Contributor
Posts: 102

Re: how to concatenate the values with two macro values as variable names in data set

Posted in reply to PaigeMiller

I want a table as data set. The percents and pass number in the exact same cell  of the dataset. 

 

Thank you

Solution
a week ago
Respected Advisor
Posts: 2,649

Re: how to concatenate the values with two macro values as variable names in data set


@daisy6 wrote:

I want a table as data set. The percents and pass number in the exact same cell  of the dataset. 


The idea of having a cell in a SAS data set that contains the text "23 (53.4%)" seems utterly useless to me. What possible use of such a data set could there be?

 

However, if you really want to do this, you create a data set where the calculations are done and there are numbers in each cell, 23 in one cell, 53.4 in another cell (PROC SUMMARY could do this easily), and then using a data step, convert these values to characters and concatenate them. I do not have the time today to advise further on the exact code. Please see if you can make this work based upon the description I have given.

 

 

--
Paige Miller
Frequent Contributor
Posts: 102

Re: how to concatenate the values with two macro values as variable names in data set

Posted in reply to PaigeMiller

PaigeMiller, thank you for your suggestions.  I used your method to solve that problem.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 119 views
  • 0 likes
  • 2 in conversation