question 1.
rename oldvar=newvar;label oldvar='label'; ----> why we should give label to oldvar even though we already renamed in datastep?
But in the proc dataset
rename oldvar=newvar;label newvar='label'; ----> why we should give label to newvar(reverse to datastep)?
question2. the following statements should be completed one after the other. need in datastep only and if possible,without point concept
data oneset twosets onemerge twomerge;
set c d; output oneset;
set c;set d;output twosets;
merge c d;output onemerge;
merge c;merge d;output twomerge;
run;
1) Does because that is how it works help?
Actually you can label the old variable name in PROC DATASETS, just do it BEFORE you rename it. PROC DATASETS is a tool for modifying data sets. So you can make multiple modifications at once. In a data step the whole step is the definition of what the output will be. You cannot change the name that you use to refer to a variable while the step is running. The RENAME statement in the data step just changes the name that the variable will have in the output data set. That is it changes how the NEXT step should reference the variable.
2) I have no idea what you are asking. The first three might make some sense but the last does not. But if you want to write out records in different order in the same step then you will need to do something that lets you manipulate the (such as the POINT= option on the SET statement). It is probably easier to not do this at all. Or if you must then it will require more than one data step.
This makes sense . You are just concatenating the two tables.
data oneset ;
set c d;
run;
What is the second one? Do you want to interleave the records from C and D? That only makes sense if the two tables are exactly the same length, otherwise the longer one will be truncated when the data step stops because it reached the end of the shorter file. Or you could use the EOF= option and test that you haven't read past the end of the shorter table. You will also need to check when to stop the data step.
data twoset;
set c;
output;
set d;
output;
run;
Third one looks like a merge. This would essentially attach the D dataset variables to the right of the C dataset variables. But you should have a BY statement.
data onemerge;
merge c d;
BY IDVAR ;
run;
Fourth one I am not sure what you want. Are you trying to make a checker board pattern where odd observations have values for the C varaibles and missing values for the D variables and the even ones the reverse?
1) Does because that is how it works help?
Actually you can label the old variable name in PROC DATASETS, just do it BEFORE you rename it. PROC DATASETS is a tool for modifying data sets. So you can make multiple modifications at once. In a data step the whole step is the definition of what the output will be. You cannot change the name that you use to refer to a variable while the step is running. The RENAME statement in the data step just changes the name that the variable will have in the output data set. That is it changes how the NEXT step should reference the variable.
2) I have no idea what you are asking. The first three might make some sense but the last does not. But if you want to write out records in different order in the same step then you will need to do something that lets you manipulate the (such as the POINT= option on the SET statement). It is probably easier to not do this at all. Or if you must then it will require more than one data step.
This makes sense . You are just concatenating the two tables.
data oneset ;
set c d;
run;
What is the second one? Do you want to interleave the records from C and D? That only makes sense if the two tables are exactly the same length, otherwise the longer one will be truncated when the data step stops because it reached the end of the shorter file. Or you could use the EOF= option and test that you haven't read past the end of the shorter table. You will also need to check when to stop the data step.
data twoset;
set c;
output;
set d;
output;
run;
Third one looks like a merge. This would essentially attach the D dataset variables to the right of the C dataset variables. But you should have a BY statement.
data onemerge;
merge c d;
BY IDVAR ;
run;
Fourth one I am not sure what you want. Are you trying to make a checker board pattern where odd observations have values for the C varaibles and missing values for the D variables and the even ones the reverse?
thanks for the reply.
I understood. the interviewer asked me this question
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.