BookmarkSubscribeRSS Feed
stancemcgraw
Obsidian | Level 7

Hello. I have 7 categorical variables that are dummy variables coded as Y or N and 2 numerical dummy variables that are coded as 1 or 0. I want to create a variable that counts the total number of 'Y' or 1'' for each of these variables. Any suggestions?

 

Data screenshot is in attachment below

 

 

4 REPLIES 4
Reeza
Super User

1. Use CATX() to combine all into one character variable.

2. Use COUNTC() to count the characters of interest. You'll probably need to call this twice, once for Y and once for N. 

 

In general, its better to store Y/N as 1/0 because then you can use SUM() or other basic math functions. 

novinosrin
Tourmaline | Level 20

I would have liked to code had you given the sample data HAVE and WANTas plain text. Screenshot,pdf or any attachments doesn't help at all.

Reeza
Super User

@novinosrin I choose to tailor my answers based on the question. No data, then you get an approach solution because I'm not going to make assumptions and have someone come back and say it doesn't work or provide sample data in a different format than I guessed. It's mostly inefficient for me.

Also, if the data is an image, the code is an image these days. It's maybe a bit petty but I think users also learn more when they have to type it out rather than copy and paste and I do follow that myself, I force myself to type it out line by line. 

 

@stancemcgraw Nothing in this post is related to you directly, more so on general behaviour on the community forums. 

novinosrin
Tourmaline | Level 20

@Reeza 🙂 true. I got that. Also, I must admit, i code here selfishly for my practice and continued learning. Honestly, not generous yet. Please don't think I am a bad person. lol. I treat this as my school indirectly benefiting OPs. Once I accomplish like you have in career and knowledge, I'd then become selfless.  Ok, i am going out for a beer. Have a great evening!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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