Hi,
PFA here test tab has raw data and result tab has expected data.
I have redundant data more than 100 records. How shall I manage this data by using macro.
Can you share/explain program by using given raw data.
Thank you in advance.
Regards
Priyanka
Raw data
Expected data -
when case(raw) has "old" data, thn "n" at the end of name(raw) that would new_name(result).
Please provide more explanation of the logic that lets you go from the input data to the output data.
Also, do not provide data via screen captures and do not provide data as Excel files (which most people will not download). Provide data using these instructions.
@PaigeMiller Can you see screenshot or attachment ? onwards i will not share any.
So you are just taking the first letter of variable CASE and appending it to the text string in variable NAME?
No macros needed. A DATA step will do the job.
data want;
set have;
length new_name $ 32;
new_name=cats(name,substr(case,1,1));
number_new=input(number,8.0);
run;
What do you mean by "query". Usually with SAS you work on DATASETS. You don't work on queries. You might RUN a query, especially if you want to use PROC SQL instead of a DATA step or some other PROC.
Please explain what input data you have, best would be to provide a small but sufficient sample to explain the issue you are have. Then explain what output you want from that data. Provide the output that would be generated if you could get the logic to work (another reason to post a small example so you can figure out yourself what output you expect).
When posting data it best to post it as text, preferable as a data step that re-creates the dataset. Then someone can re-create your example in their SAS session and give you a tested program. When you post photographs of data then it will make it harder for people to help you. And many people will not (are not allowed to) download attachments.
This is going nowhere.
Please provide data in usable form (data step with datalines), and the end result you want to get out of it.
Without knowing the "here" and "there", it is virtually impossible to show you how to get there from here.
Sure when share soon
It sounds like you have a variable NAME that does not form a unique key for your dataset. That is the same value of NAME appears on multiple observations. And you want to create a new dataset where the value of NAME is unique. You seem to think you could get there by appending the first letter of the variable CASE.
For example if your source dataset is named HAVE and the two variables are named NAME and CASE then this data step will generate a new variable named NEW_NAME the appends the first letter of CASE to the end of NAME. Since you didn't show how NAME is defined I just assumed that a length of 30 bytes would be enough NEW_NAME.
data want;
set have ;
length new_name $30 ;
new_name=cats(name,char(case,1));
run;
But if you can explain more about the overall operation you are trying to do perhaps there is another way, or a better way. For example if the goal is just to uniquely identify the observations in the dataset why not just use both NAME and CASE as the key variables (BY variables)?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.