BookmarkSubscribeRSS Feed
pdhokriya
Pyrite | Level 9

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

pdhokriya_0-1611595311618.png

Expected data - 

 

when case(raw) has "old" data,  thn "n" at the end of name(raw) that would new_name(result).

pdhokriya_1-1611595372993.png

 

11 REPLIES 11
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
pdhokriya
Pyrite | Level 9
for 1st record -

if name = "abcd" and case = "new" then do;
new_name = "abcdn" ;
number_new = input(number,best.);
end;

I am using same query many time to get final dataset. Is there any other option ?

pdhokriya
Pyrite | Level 9

@PaigeMiller Can you see screenshot or attachment ? onwards i will not share any.

PaigeMiller
Diamond | Level 26

So you are just taking the first letter of variable CASE and appending it to the text string in variable NAME?

--
Paige Miller
pdhokriya
Pyrite | Level 9
ya its a part of my query. addition to that how shall I call my variable data ?
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
pdhokriya
Pyrite | Level 9
I think u miss understood my query.

I had a qery when I have huge data how can i handle , to just avoid multiple steps

i.e. if name = "abcd" and case = "new" then do;
new_name = "abcdn" ;
number_new = input(number,best.);
end;

for above mentioned data to avoid multiple lines of program
Tom
Super User Tom
Super User

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.

 

Kurt_Bremser
Super User

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.

pdhokriya
Pyrite | Level 9

Sure when share soon

Tom
Super User Tom
Super User

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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